@gala-chain/launchpad-sdk 3.9.1 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +396 -18
- package/dist/LaunchpadSDK.d.ts +169 -3
- package/dist/LaunchpadSDK.d.ts.map +1 -1
- package/dist/api/LaunchpadAPI.d.ts +108 -0
- package/dist/api/LaunchpadAPI.d.ts.map +1 -1
- package/dist/constants/config.d.ts +30 -0
- package/dist/constants/config.d.ts.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/services/LaunchpadService.d.ts +21 -0
- package/dist/services/LaunchpadService.d.ts.map +1 -1
- package/dist/services/PoolService.d.ts +53 -0
- package/dist/services/PoolService.d.ts.map +1 -1
- package/dist/services/TokenMetadataCache.d.ts +242 -0
- package/dist/services/TokenMetadataCache.d.ts.map +1 -0
- package/dist/utils/cacheWarmingHelpers.d.ts +110 -0
- package/dist/utils/cacheWarmingHelpers.d.ts.map +1 -0
- package/package.json +2 -1
|
@@ -68,9 +68,15 @@ export declare class LaunchpadService {
|
|
|
68
68
|
/**
|
|
69
69
|
* Fetches pools with filtering and pagination
|
|
70
70
|
*
|
|
71
|
+
* Supports automatic multi-page fetching:
|
|
72
|
+
* - `limit <= 20`: Single API call (backward compatible)
|
|
73
|
+
* - `limit > 20`: Automatic concurrent multi-page fetching
|
|
74
|
+
* - `limit === 0`: Fetches all available pools
|
|
75
|
+
*
|
|
71
76
|
* @param options Fetch options including type, search, and pagination
|
|
72
77
|
* @returns Promise<PoolsResult> Clean pool data with full pagination
|
|
73
78
|
* @since 2.0.0
|
|
79
|
+
* @updated 3.11.0 - Added auto-pagination support
|
|
74
80
|
*/
|
|
75
81
|
fetchPools(options?: {
|
|
76
82
|
search?: string;
|
|
@@ -79,6 +85,21 @@ export declare class LaunchpadService {
|
|
|
79
85
|
page?: number;
|
|
80
86
|
limit?: number;
|
|
81
87
|
}): Promise<PoolsResult>;
|
|
88
|
+
/**
|
|
89
|
+
* Fetches all available pools with automatic pagination
|
|
90
|
+
*
|
|
91
|
+
* Convenience method that fetches all available pools. Delegates to PoolService.
|
|
92
|
+
* Equivalent to `fetchPools({ ...options, limit: 0 })`.
|
|
93
|
+
*
|
|
94
|
+
* @param options Optional filters (type, tokenName, search)
|
|
95
|
+
* @returns Promise<PoolsResult> with all pools
|
|
96
|
+
* @since 3.11.0
|
|
97
|
+
*/
|
|
98
|
+
fetchAllPools(options?: {
|
|
99
|
+
search?: string;
|
|
100
|
+
tokenName?: string;
|
|
101
|
+
type?: 'recent' | 'popular';
|
|
102
|
+
}): Promise<PoolsResult>;
|
|
82
103
|
/**
|
|
83
104
|
* Checks if a pool exists for given token name or symbol
|
|
84
105
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LaunchpadService.d.ts","sourceRoot":"","sources":["../../src/services/LaunchpadService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAQ5C,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB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IACG,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ/D;;;;;OAKG;IACH,UAAU,IAAI,MAAM;IAIpB;;;;;;OAMG;IACH,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAG3C"}
|
|
@@ -34,11 +34,40 @@ import { FetchVolumeDataOptions, HasTokenBadgeOptions } from '../types/options.d
|
|
|
34
34
|
export declare class PoolService {
|
|
35
35
|
private readonly http;
|
|
36
36
|
constructor(http: HttpClient);
|
|
37
|
+
/**
|
|
38
|
+
* Fetches a single page of pools (internal helper)
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
private fetchSinglePage;
|
|
42
|
+
/**
|
|
43
|
+
* Fetches multiple pages of pools concurrently with rate limiting
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
private fetchMultiplePages;
|
|
37
47
|
/**
|
|
38
48
|
* Fetches pools with filtering and pagination
|
|
39
49
|
*
|
|
50
|
+
* Supports automatic multi-page fetching:
|
|
51
|
+
* - `limit <= 20`: Single API call (backward compatible)
|
|
52
|
+
* - `limit > 20`: Automatic concurrent multi-page fetching
|
|
53
|
+
* - `limit === 0`: Fetches all available pools
|
|
54
|
+
*
|
|
40
55
|
* @param options Fetch options including type, search, and pagination
|
|
41
56
|
* @returns Promise<PoolsResult> Clean pool data with full pagination
|
|
57
|
+
* @since 3.6.0
|
|
58
|
+
* @updated 3.11.0 - Added auto-pagination support
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // Single page fetch (backward compatible)
|
|
63
|
+
* const result1 = await poolService.fetchPools({ limit: 20 });
|
|
64
|
+
*
|
|
65
|
+
* // Auto-pagination (fetches 5 pages concurrently: 20+20+20+20+20)
|
|
66
|
+
* const result2 = await poolService.fetchPools({ limit: 100 });
|
|
67
|
+
*
|
|
68
|
+
* // Fetch all pools
|
|
69
|
+
* const result3 = await poolService.fetchPools({ limit: 0 });
|
|
70
|
+
* ```
|
|
42
71
|
*/
|
|
43
72
|
fetchPools(options?: {
|
|
44
73
|
search?: string;
|
|
@@ -47,6 +76,30 @@ export declare class PoolService {
|
|
|
47
76
|
page?: number;
|
|
48
77
|
limit?: number;
|
|
49
78
|
}): Promise<PoolsResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Fetches all available pools with automatic pagination
|
|
81
|
+
*
|
|
82
|
+
* Convenience method that fetches all available pools by automatically
|
|
83
|
+
* handling pagination. Equivalent to `fetchPools({ ...options, limit: 0 })`.
|
|
84
|
+
*
|
|
85
|
+
* @param options Optional filters (type, tokenName, search)
|
|
86
|
+
* @returns Promise<PoolsResult> with all pools
|
|
87
|
+
* @since 3.11.0
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // Fetch all recent pools
|
|
92
|
+
* const all = await poolService.fetchAllPools({ type: 'recent' });
|
|
93
|
+
*
|
|
94
|
+
* // Fetch all pools matching search
|
|
95
|
+
* const matching = await poolService.fetchAllPools({ search: 'dragon' });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
fetchAllPools(options?: {
|
|
99
|
+
search?: string;
|
|
100
|
+
tokenName?: string;
|
|
101
|
+
type?: 'recent' | 'popular';
|
|
102
|
+
}): Promise<PoolsResult>;
|
|
50
103
|
/**
|
|
51
104
|
* Checks if a pool exists for given token name or symbol
|
|
52
105
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PoolService.d.ts","sourceRoot":"","sources":["../../src/services/PoolService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"PoolService.d.ts","sourceRoot":"","sources":["../../src/services/PoolService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAU3C,O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;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,uBAAuB,CAAC;IAoCnC;;;;;;;;OAQG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAwBrE;;;;;OAKG;IACG,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC;IAkBpE;;;;;;;;;;;;;;;;OAgBG;IACG,uBAAuB,CAC3B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAoB1B"}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token Metadata Cache Service
|
|
3
|
+
*
|
|
4
|
+
* High-performance in-memory cache for immutable token metadata, optimized for
|
|
5
|
+
* local bonding curve calculations. Eliminates redundant API calls by caching:
|
|
6
|
+
* - Reverse bonding curve fee factors (from fetchPools)
|
|
7
|
+
* - Custom maxSupply values (auto-detected, defaults to 10M constant)
|
|
8
|
+
* - Vault addresses (via TokenResolverService)
|
|
9
|
+
*
|
|
10
|
+
* Cache persistence: Entire MCP server lifetime (survives across conversations)
|
|
11
|
+
*
|
|
12
|
+
* @category Services
|
|
13
|
+
* @since 3.9.2
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Token metadata cache entry
|
|
17
|
+
*
|
|
18
|
+
* Stores immutable token properties needed for local calculations.
|
|
19
|
+
* All properties are optional - cache can be partially populated.
|
|
20
|
+
*/
|
|
21
|
+
export interface TokenMetadata {
|
|
22
|
+
/** Minimum reverse bonding curve fee factor (0.0 - 1.0) */
|
|
23
|
+
reverseBondingCurveMinFeeFactor?: number;
|
|
24
|
+
/** Maximum reverse bonding curve fee factor (0.0 - 1.0) */
|
|
25
|
+
reverseBondingCurveMaxFeeFactor?: number;
|
|
26
|
+
/** Net reverse bonding curve fee factor (max - min) */
|
|
27
|
+
reverseBondingCurveNetFeeFactor?: number;
|
|
28
|
+
/** Vault address for this token (GalaChain format) */
|
|
29
|
+
vaultAddress?: string;
|
|
30
|
+
/** Custom maximum supply (only cached if != default 10M) */
|
|
31
|
+
maxSupply?: string;
|
|
32
|
+
/** Timestamp when this cache entry was last updated */
|
|
33
|
+
lastUpdated: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Cache statistics for monitoring and debugging
|
|
37
|
+
*/
|
|
38
|
+
export interface CacheStats {
|
|
39
|
+
/** Total number of tokens in cache */
|
|
40
|
+
totalTokens: number;
|
|
41
|
+
/** Approximate cache size in bytes */
|
|
42
|
+
cacheSize: number;
|
|
43
|
+
/** Timestamp of oldest cache entry */
|
|
44
|
+
oldestEntry: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Token Metadata Cache
|
|
48
|
+
*
|
|
49
|
+
* High-performance in-memory cache for immutable token properties used in local calculations.
|
|
50
|
+
*
|
|
51
|
+
* ## Cache Lifecycle
|
|
52
|
+
* - **Persistence**: Entire MCP server lifetime (survives across conversations)
|
|
53
|
+
* - **Bounded Size**: Maximum 10,000 tokens (~2.5MB max memory)
|
|
54
|
+
* - **Eviction Strategy**: LRU (Least Recently Updated) with O(1) eviction time
|
|
55
|
+
*
|
|
56
|
+
* ## Warming Strategy (Opportunistic Caching)
|
|
57
|
+
* Cache is automatically warmed during normal SDK operations:
|
|
58
|
+
* - `fetchPools()` - Caches RBC fees and vault addresses for all returned pools
|
|
59
|
+
* - `fetchPoolDetailsForCalculation()` - Caches maxSupply and RBC fees (including defaults)
|
|
60
|
+
* - `fetchCurrentSupply()` - Caches maxSupply when fetched
|
|
61
|
+
* - `fetchTokenDistribution()` - Caches vault address when resolved
|
|
62
|
+
*
|
|
63
|
+
* ## Performance Characteristics
|
|
64
|
+
* - **Get/Set**: O(1) average time complexity
|
|
65
|
+
* - **Eviction**: O(1) time (uses Map insertion order)
|
|
66
|
+
* - **Normalization**: Handles unicode, case-insensitive, whitespace cleanup
|
|
67
|
+
* - **Memory**: ~250-400 bytes per entry (depends on string field lengths)
|
|
68
|
+
*
|
|
69
|
+
* ## Smart Defaults
|
|
70
|
+
* - **maxSupply**: Returns constant 10M for uncached tokens (99%+ hit rate)
|
|
71
|
+
* - **RBC Fees**: Defensive defaults (0.0 min, 0.5 max) when API data missing
|
|
72
|
+
*
|
|
73
|
+
* @example Basic usage
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const cache = new TokenMetadataCache();
|
|
76
|
+
*
|
|
77
|
+
* // Warm cache from pool data
|
|
78
|
+
* cache.warmFromPoolData('anime', {
|
|
79
|
+
* reverseBondingCurveMinFeeFactor: 0.0,
|
|
80
|
+
* reverseBondingCurveMaxFeeFactor: 0.5
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // Retrieve cached data
|
|
84
|
+
* const metadata = cache.get('anime');
|
|
85
|
+
* const maxSupply = cache.getMaxSupply('anime'); // Returns '10000000' (default)
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @category Services
|
|
89
|
+
* @since 3.9.2
|
|
90
|
+
*/
|
|
91
|
+
export declare class TokenMetadataCache {
|
|
92
|
+
/** Maximum cache size (10,000 tokens ≈ 2.5MB max memory) */
|
|
93
|
+
private static readonly MAX_CACHE_SIZE;
|
|
94
|
+
private cache;
|
|
95
|
+
/**
|
|
96
|
+
* Get least recently updated entry for LRU eviction
|
|
97
|
+
*
|
|
98
|
+
* Leverages Map's insertion order: the first key is the oldest.
|
|
99
|
+
* O(1) time complexity vs O(n) scanning.
|
|
100
|
+
*
|
|
101
|
+
* @returns Token name of oldest entry, or null if cache is empty
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
private getLRUKey;
|
|
105
|
+
/**
|
|
106
|
+
* Normalize token name for consistent cache keys
|
|
107
|
+
*
|
|
108
|
+
* Handles edge cases: unicode control chars, multiple spaces, case insensitivity.
|
|
109
|
+
*
|
|
110
|
+
* @param tokenName Raw token name
|
|
111
|
+
* @returns Normalized token name (lowercase, trimmed, cleaned)
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
private normalizeTokenName;
|
|
115
|
+
/**
|
|
116
|
+
* Warm cache from pool data (opportunistic caching from fetchPools)
|
|
117
|
+
*
|
|
118
|
+
* Partially populates cache with reverse bonding curve fees and vault address
|
|
119
|
+
* from fetchPools response. This provides zero-cost cache warming during normal
|
|
120
|
+
* pool browsing operations.
|
|
121
|
+
*
|
|
122
|
+
* @param tokenName Token name (normalized to lowercase)
|
|
123
|
+
* @param poolData Partial metadata from pool data
|
|
124
|
+
*
|
|
125
|
+
* @example Warming from fetchPools
|
|
126
|
+
* ```typescript
|
|
127
|
+
* pools.forEach(pool => {
|
|
128
|
+
* cache.warmFromPoolData(pool.tokenName, {
|
|
129
|
+
* reverseBondingCurveMinFeeFactor: parseFloat(pool.reverseBondingCurveMinFeePortion),
|
|
130
|
+
* reverseBondingCurveMaxFeeFactor: parseFloat(pool.reverseBondingCurveMaxFeePortion),
|
|
131
|
+
* vaultAddress: pool.vaultAddress
|
|
132
|
+
* });
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
warmFromPoolData(tokenName: string, poolData: Partial<TokenMetadata>): void;
|
|
137
|
+
/**
|
|
138
|
+
* Set or update cache entry for a token
|
|
139
|
+
*
|
|
140
|
+
* Updates cache with partial or complete metadata. Merges with existing data.
|
|
141
|
+
*
|
|
142
|
+
* @param tokenName Token name (normalized to lowercase)
|
|
143
|
+
* @param metadata Partial or complete metadata to cache
|
|
144
|
+
*
|
|
145
|
+
* @example Caching custom maxSupply
|
|
146
|
+
* ```typescript
|
|
147
|
+
* cache.set('customtoken', {
|
|
148
|
+
* maxSupply: '50000000' // Custom max supply detected
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
set(tokenName: string, metadata: Partial<TokenMetadata>): void;
|
|
153
|
+
/**
|
|
154
|
+
* Get cached metadata for a token
|
|
155
|
+
*
|
|
156
|
+
* @param tokenName Token name (normalized to lowercase)
|
|
157
|
+
* @returns Cached metadata or null if not cached
|
|
158
|
+
*
|
|
159
|
+
* @example Retrieving cached data
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const metadata = cache.get('anime');
|
|
162
|
+
* if (metadata?.reverseBondingCurveMaxFeeFactor) {
|
|
163
|
+
* console.log('RBC max fee:', metadata.reverseBondingCurveMaxFeeFactor);
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
get(tokenName: string): TokenMetadata | null;
|
|
168
|
+
/**
|
|
169
|
+
* Get maxSupply for a token (returns cached or default constant)
|
|
170
|
+
*
|
|
171
|
+
* Returns cached custom maxSupply if available, otherwise returns the
|
|
172
|
+
* default constant (10,000,000). This eliminates the need to fetch maxSupply
|
|
173
|
+
* for 99%+ of tokens that use the default value.
|
|
174
|
+
*
|
|
175
|
+
* @param tokenName Token name (normalized to lowercase)
|
|
176
|
+
* @returns maxSupply as decimal string (cached or default '10000000')
|
|
177
|
+
*
|
|
178
|
+
* @example Getting maxSupply with fallback
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const maxSupply = cache.getMaxSupply('anime'); // '10000000' (default)
|
|
181
|
+
* const customSupply = cache.getMaxSupply('customtoken'); // '50000000' (cached custom)
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
getMaxSupply(tokenName: string): string;
|
|
185
|
+
/**
|
|
186
|
+
* Check if a token exists in cache
|
|
187
|
+
*
|
|
188
|
+
* @param tokenName Token name (normalized to lowercase)
|
|
189
|
+
* @returns True if token has any cached metadata
|
|
190
|
+
*/
|
|
191
|
+
has(tokenName: string): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Clear cache (all tokens or specific token)
|
|
194
|
+
*
|
|
195
|
+
* @param tokenName Optional token name to clear (clears all if not provided)
|
|
196
|
+
*
|
|
197
|
+
* @example Clear specific token
|
|
198
|
+
* ```typescript
|
|
199
|
+
* cache.clear('anime'); // Clear only anime token
|
|
200
|
+
* ```
|
|
201
|
+
*
|
|
202
|
+
* @example Clear entire cache
|
|
203
|
+
* ```typescript
|
|
204
|
+
* cache.clear(); // Clear all tokens
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
clear(tokenName?: string): void;
|
|
208
|
+
/**
|
|
209
|
+
* Export entire cache as plain object
|
|
210
|
+
*
|
|
211
|
+
* Useful for debugging, monitoring, and cache inspection.
|
|
212
|
+
*
|
|
213
|
+
* @returns Cache contents as plain object (tokenName -> metadata)
|
|
214
|
+
*
|
|
215
|
+
* @example Dump cache for debugging
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const cacheData = cache.dump();
|
|
218
|
+
* console.log('Cached tokens:', Object.keys(cacheData));
|
|
219
|
+
* console.log('Cache contents:', JSON.stringify(cacheData, null, 2));
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
dump(): Record<string, TokenMetadata>;
|
|
223
|
+
/**
|
|
224
|
+
* Get cache statistics
|
|
225
|
+
*
|
|
226
|
+
* Returns statistics about cache size and age for monitoring performance.
|
|
227
|
+
*
|
|
228
|
+
* ⚠️ **Performance**: O(n) - iterates over all cache entries to calculate size.
|
|
229
|
+
* Do not call in hot paths or frequently.
|
|
230
|
+
*
|
|
231
|
+
* @returns Cache statistics
|
|
232
|
+
*
|
|
233
|
+
* @example Get cache stats
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const stats = cache.stats();
|
|
236
|
+
* console.log(`Cached ${stats.totalTokens} tokens (${stats.cacheSize} bytes)`);
|
|
237
|
+
* console.log(`Oldest entry: ${new Date(stats.oldestEntry).toISOString()}`);
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
stats(): CacheStats;
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=TokenMetadataCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenMetadataCache.d.ts","sourceRoot":"","sources":["../../src/services/TokenMetadataCache.ts"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AAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAQvC;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAK/B;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAS/B;;;;;;;;;;;;;OAaG;IACH,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC;IAQrC;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,IAAI,UAAU;CAsCpB"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Warming Helpers
|
|
3
|
+
*
|
|
4
|
+
* Shared utilities for extracting and caching token metadata from pool data.
|
|
5
|
+
* This module provides type-safe, reusable logic for opportunistic cache warming
|
|
6
|
+
* that can be used across the SDK codebase.
|
|
7
|
+
*
|
|
8
|
+
* @category Utilities
|
|
9
|
+
* @since 3.9.2
|
|
10
|
+
*/
|
|
11
|
+
import type { TokenMetadata } from '../services/TokenMetadataCache';
|
|
12
|
+
/**
|
|
13
|
+
* Pool data fields relevant for cache warming
|
|
14
|
+
*
|
|
15
|
+
* This is a focused subset of PoolData containing only fields needed
|
|
16
|
+
* for metadata extraction. Using a minimal interface keeps cache warming
|
|
17
|
+
* logic decoupled from full pool data structure.
|
|
18
|
+
*/
|
|
19
|
+
export interface PoolDataForCaching {
|
|
20
|
+
/** Token name (required for cache key) */
|
|
21
|
+
tokenName: string;
|
|
22
|
+
/** Vault address (GalaChain format) */
|
|
23
|
+
vaultAddress?: string;
|
|
24
|
+
/** Reverse bonding curve minimum fee portion (string representation) */
|
|
25
|
+
reverseBondingCurveMinFeePortion?: string;
|
|
26
|
+
/** Reverse bonding curve maximum fee portion (string representation) */
|
|
27
|
+
reverseBondingCurveMaxFeePortion?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extract cacheable metadata from pool data
|
|
31
|
+
*
|
|
32
|
+
* Converts pool API response data into structured token metadata suitable
|
|
33
|
+
* for caching. Handles string-to-number conversion, validation, and derived
|
|
34
|
+
* calculations (net fee factor).
|
|
35
|
+
*
|
|
36
|
+
* This is a pure function with no side effects - it only extracts and transforms data.
|
|
37
|
+
*
|
|
38
|
+
* @param pool - Pool data from API (must have tokenName field)
|
|
39
|
+
* @param logger - Optional logger for debugging invalid data
|
|
40
|
+
* @returns Metadata object if any fields could be extracted, null otherwise
|
|
41
|
+
*
|
|
42
|
+
* @example Basic extraction
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const pool = {
|
|
45
|
+
* tokenName: 'anime',
|
|
46
|
+
* vaultAddress: 'service|Token$Unit$ANIME$...',
|
|
47
|
+
* reverseBondingCurveMinFeePortion: '0.0',
|
|
48
|
+
* reverseBondingCurveMaxFeePortion: '0.5'
|
|
49
|
+
* };
|
|
50
|
+
*
|
|
51
|
+
* const metadata = extractMetadataFromPoolData(pool);
|
|
52
|
+
* // Returns:
|
|
53
|
+
* // {
|
|
54
|
+
* // vaultAddress: 'service|Token$Unit$ANIME$...',
|
|
55
|
+
* // reverseBondingCurveMinFeeFactor: 0.0,
|
|
56
|
+
* // reverseBondingCurveMaxFeeFactor: 0.5,
|
|
57
|
+
* // reverseBondingCurveNetFeeFactor: 0.5
|
|
58
|
+
* // }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example With invalid data (graceful handling)
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const pool = {
|
|
64
|
+
* tokenName: 'test',
|
|
65
|
+
* reverseBondingCurveMinFeePortion: 'invalid' // NaN after parseFloat
|
|
66
|
+
* };
|
|
67
|
+
*
|
|
68
|
+
* const metadata = extractMetadataFromPoolData(pool, logger);
|
|
69
|
+
* // Returns: null (no valid metadata)
|
|
70
|
+
* // Logger outputs: "Skipping invalid reverseBondingCurveMinFeePortion for test: 'invalid'"
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example Partial metadata (some fields missing)
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const pool = {
|
|
76
|
+
* tokenName: 'partial',
|
|
77
|
+
* vaultAddress: 'service|...'
|
|
78
|
+
* // No RBC fee data
|
|
79
|
+
* };
|
|
80
|
+
*
|
|
81
|
+
* const metadata = extractMetadataFromPoolData(pool);
|
|
82
|
+
* // Returns: { vaultAddress: 'service|...' }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function extractMetadataFromPoolData(pool: PoolDataForCaching, logger?: {
|
|
86
|
+
debug: (message: string) => void;
|
|
87
|
+
}): Partial<TokenMetadata> | null;
|
|
88
|
+
/**
|
|
89
|
+
* Validate pool data structure for cache warming
|
|
90
|
+
*
|
|
91
|
+
* Checks that pool data has required fields and correct types before attempting
|
|
92
|
+
* metadata extraction. This prevents runtime errors from malformed API responses.
|
|
93
|
+
*
|
|
94
|
+
* @param pool - Pool data to validate
|
|
95
|
+
* @returns True if pool data is valid for caching, false otherwise
|
|
96
|
+
*
|
|
97
|
+
* @example Valid pool data
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const pool = { tokenName: 'anime', vaultAddress: '...' };
|
|
100
|
+
* isValidPoolForCaching(pool); // true
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example Invalid pool data
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const badPool = { vaultAddress: '...' }; // Missing tokenName
|
|
106
|
+
* isValidPoolForCaching(badPool); // false
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function isValidPoolForCaching(pool: any): pool is PoolDataForCaching;
|
|
110
|
+
//# sourceMappingURL=cacheWarmingHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cacheWarmingHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/cacheWarmingHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAGpE;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,gCAAgC,CAAC,EAAE,MAAM,CAAC;IAC1C,wEAAwE;IACxE,gCAAgC,CAAC,EAAE,MAAM,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,kBAAkB,EACxB,MAAM,CAAC,EAAE;IAAE,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,GAC5C,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CA2C/B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,kBAAkB,CAQ3E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gala-chain/launchpad-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"description": "TypeScript SDK for Gala Launchpad Backend API - Production-ready DeFi token launchpad integration with wallet-based authentication, GalaChain trading, and comprehensive user operations. 100% tested (22/22 endpoints working).",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"test:ci": "jest --coverage --ci --watchAll=false",
|
|
39
39
|
"demo": "tsx examples/complete-sdk-demo.ts",
|
|
40
40
|
"demo-trades": "tsx examples/demo-trades.ts",
|
|
41
|
+
"demo-cache": "tsx examples/demo-cache.ts",
|
|
41
42
|
"lint": "eslint src --ext .ts,.tsx --fix",
|
|
42
43
|
"lint:check": "eslint src --ext .ts,.tsx",
|
|
43
44
|
"typecheck": "tsc --noEmit",
|