@flashnet/sdk 0.1.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.
Files changed (50) hide show
  1. package/README.md +479 -0
  2. package/dist/index.d.ts +13 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +15 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/src/api/client.d.ts +20 -0
  7. package/dist/src/api/client.d.ts.map +1 -0
  8. package/dist/src/api/client.js +85 -0
  9. package/dist/src/api/client.js.map +1 -0
  10. package/dist/src/api/typed-endpoints.d.ts +135 -0
  11. package/dist/src/api/typed-endpoints.d.ts.map +1 -0
  12. package/dist/src/api/typed-endpoints.js +202 -0
  13. package/dist/src/api/typed-endpoints.js.map +1 -0
  14. package/dist/src/api/validation.d.ts +114 -0
  15. package/dist/src/api/validation.d.ts.map +1 -0
  16. package/dist/src/api/validation.js +128 -0
  17. package/dist/src/api/validation.js.map +1 -0
  18. package/dist/src/client/FlashnetClient.d.ts +216 -0
  19. package/dist/src/client/FlashnetClient.d.ts.map +1 -0
  20. package/dist/src/client/FlashnetClient.js +800 -0
  21. package/dist/src/client/FlashnetClient.js.map +1 -0
  22. package/dist/src/config/index.d.ts +14 -0
  23. package/dist/src/config/index.d.ts.map +1 -0
  24. package/dist/src/config/index.js +40 -0
  25. package/dist/src/config/index.js.map +1 -0
  26. package/dist/src/types/index.d.ts +484 -0
  27. package/dist/src/types/index.d.ts.map +1 -0
  28. package/dist/src/types/index.js +2 -0
  29. package/dist/src/types/index.js.map +1 -0
  30. package/dist/src/utils/auth.d.ts +26 -0
  31. package/dist/src/utils/auth.d.ts.map +1 -0
  32. package/dist/src/utils/auth.js +85 -0
  33. package/dist/src/utils/auth.js.map +1 -0
  34. package/dist/src/utils/index.d.ts +8 -0
  35. package/dist/src/utils/index.d.ts.map +1 -0
  36. package/dist/src/utils/index.js +19 -0
  37. package/dist/src/utils/index.js.map +1 -0
  38. package/dist/src/utils/intents.d.ts +86 -0
  39. package/dist/src/utils/intents.d.ts.map +1 -0
  40. package/dist/src/utils/intents.js +133 -0
  41. package/dist/src/utils/intents.js.map +1 -0
  42. package/dist/src/utils/signer.d.ts +29 -0
  43. package/dist/src/utils/signer.d.ts.map +1 -0
  44. package/dist/src/utils/signer.js +34 -0
  45. package/dist/src/utils/signer.js.map +1 -0
  46. package/dist/src/utils/spark-address.d.ts +60 -0
  47. package/dist/src/utils/spark-address.d.ts.map +1 -0
  48. package/dist/src/utils/spark-address.js +227 -0
  49. package/dist/src/utils/spark-address.js.map +1 -0
  50. package/package.json +43 -0
package/README.md ADDED
@@ -0,0 +1,479 @@
1
+ # Flashnet SDK
2
+
3
+ A comprehensive SDK for interacting with Flashnet's Spark wallet and AMM (Automated Market Maker) functionality.
4
+
5
+ ## Features
6
+
7
+ - **Spark Wallet Integration** - Full wallet functionality based on `@buildonspark/issuer-sdk` or `@buildonspark/spark-sdk`
8
+ - **AMM Operations** - Create pools (single-sided & constant product), swap tokens, add/remove liquidity
9
+ - **Multi-Network Support** - Works across Mainnet and Regtest
10
+ - **Intent-Based Signing** - Secure transaction signing with intent messages
11
+ - **Custom Signers** - Support for arbitrary signing implementations (hardware wallets, remote signers, etc.)
12
+ - **TypeScript First** - Full type safety and IntelliSense support
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ bun add @flashnet/sdk
18
+ # or
19
+ npm install @flashnet/sdk
20
+ # or
21
+ yarn add @flashnet/sdk
22
+ ```
23
+
24
+ ## Usage Options
25
+
26
+ The Flashnet SDK offers two approaches to suit different needs:
27
+
28
+ ### 1. Full Client (Recommended for most users)
29
+
30
+ Use `FlashnetClient` for a complete, ready-to-use solution with automatic network detection, authentication, and balance checking.
31
+
32
+ ```typescript
33
+ import { FlashnetClient } from "@flashnet/sdk";
34
+ import { IssuerSparkWallet } from "@buildonspark/issuer-sdk";
35
+
36
+ // Initialize wallet
37
+ const { wallet } = await IssuerSparkWallet.initialize({
38
+ mnemonicOrSeed: "your-mnemonic",
39
+ options: { network: "MAINNET" },
40
+ });
41
+
42
+ // Create client - handles everything automatically
43
+ const client = new FlashnetClient(wallet);
44
+ await client.initialize(); // Auto-detects network and authenticates
45
+
46
+ // Ready to use!
47
+ const pools = await client.listPools();
48
+ const swapResult = await client.executeSwap({
49
+ poolId: "pool-id",
50
+ assetInTokenPublicKey: "token-in",
51
+ assetOutTokenPublicKey: "token-out",
52
+ amountIn: 1000000n,
53
+ minAmountOut: 950000n,
54
+ maxSlippageBps: 500,
55
+ });
56
+ ```
57
+
58
+ ### 2. 🧩 Modular Components (For advanced customization)
59
+
60
+ Build your own client using individual SDK components for maximum flexibility.
61
+
62
+ ```typescript
63
+ import {
64
+ ApiClient,
65
+ AuthManager,
66
+ getNetworkConfig,
67
+ generatePoolSwapIntentMessage,
68
+ type NetworkType,
69
+ } from "@flashnet/sdk";
70
+
71
+ // Manual setup
72
+ const network: NetworkType = "MAINNET";
73
+ const config = getNetworkConfig(network);
74
+ const apiClient = new ApiClient(config);
75
+
76
+ // Custom authentication
77
+ const authManager = new AuthManager(apiClient, publicKey, customSigner);
78
+ await authManager.authenticate();
79
+
80
+ // Direct API calls
81
+ const pools = await apiClient.ammGet("/v1/pools");
82
+ ```
83
+
84
+ ## When to Use Each Approach
85
+
86
+ ### Use FlashnetClient when:
87
+
88
+ - ✅ You want to get started quickly
89
+ - ✅ You're using a standard SparkWallet
90
+ - ✅ You want automatic network detection from wallet
91
+ - ✅ You want built-in balance checking
92
+ - ✅ You need all standard AMM operations
93
+
94
+ ### Use Modular Components when:
95
+
96
+ - ✅ You need custom authentication logic
97
+ - ✅ You're integrating with existing infrastructure
98
+ - ✅ You want fine-grained control over API calls
99
+ - ✅ You're building a specialized application
100
+ - ✅ You need to mix AMM operations with other protocols
101
+
102
+ ## Quick Start Examples
103
+
104
+ ### Using FlashnetClient (Full Client)
105
+
106
+ ```typescript
107
+ import { FlashnetClient } from "@flashnet/sdk";
108
+ import { IssuerSparkWallet } from "@buildonspark/issuer-sdk";
109
+
110
+ // Initialize wallet and client
111
+ const { wallet } = await IssuerSparkWallet.initialize({
112
+ mnemonicOrSeed: process.env.MNEMONIC,
113
+ });
114
+
115
+ const client = new FlashnetClient(wallet);
116
+
117
+ // Check balance
118
+ const balance = await client.getBalance();
119
+ console.log(`BTC: ${balance.balance} sats`);
120
+ console.log(`Tokens: ${balance.tokenBalances.size}`);
121
+
122
+ // Create a constant product pool with initial liquidity
123
+ const pool = await client.createConstantProductPool({
124
+ assetATokenPublicKey: "token-pubkey",
125
+ assetBTokenPublicKey: BTC_ASSET_PUBKEY,
126
+ lpFeeRateBps: 30, // 0.3%
127
+ totalHostFeeRateBps: 10, // 0.1%
128
+ initialLiquidity: {
129
+ assetAAmount: 1000000n,
130
+ assetBAmount: 5000n,
131
+ },
132
+ });
133
+
134
+ // Execute a swap (with automatic balance checking)
135
+ const swap = await client.executeSwap({
136
+ poolId: pool.poolId,
137
+ assetInTokenPublicKey: "token-in",
138
+ assetOutTokenPublicKey: BTC_ASSET_PUBKEY,
139
+ amountIn: 100000n,
140
+ minAmountOut: 450n,
141
+ maxSlippageBps: 500, // 5% slippage tolerance
142
+ });
143
+ ```
144
+
145
+ ### Using Modular Components
146
+
147
+ ```typescript
148
+ import {
149
+ ApiClient,
150
+ AuthManager,
151
+ getNetworkConfig,
152
+ encodeSparkAddress,
153
+ generatePoolSwapIntentMessage,
154
+ generateNonce,
155
+ createWalletSigner,
156
+ } from "@flashnet/sdk";
157
+
158
+ // Setup
159
+ const config = getNetworkConfig("MAINNET");
160
+ const apiClient = new ApiClient(config);
161
+ const api = apiClient.amm; // Typed API endpoints
162
+
163
+ // Authenticate with wallet
164
+ const signer = createWalletSigner(wallet);
165
+ const authManager = new AuthManager(apiClient, publicKey, signer);
166
+ const token = await authManager.authenticate();
167
+ apiClient.setAuthToken(token);
168
+
169
+ // Use typed endpoints
170
+ const pools = await api.listPools({
171
+ limit: 10,
172
+ sort: "tvlDesc",
173
+ minTvl: 1000000, // $10k minimum
174
+ });
175
+
176
+ // Manual swap flow
177
+ const simulation = await api.simulateSwap({
178
+ poolId: "pool-id",
179
+ assetInTokenPublicKey: "token-in",
180
+ assetOutTokenPublicKey: "token-out",
181
+ amountIn: 1000000,
182
+ });
183
+
184
+ // Generate and sign intent
185
+ const intentMessage = generatePoolSwapIntentMessage({
186
+ userPublicKey: publicKey,
187
+ lpIdentityPublicKey: poolId,
188
+ assetASparkTransferId: transferId,
189
+ assetInTokenPublicKey: "token-in",
190
+ assetOutTokenPublicKey: "token-out",
191
+ amountIn: "1000000",
192
+ minAmountOut: "950000",
193
+ maxSlippageBps: "500",
194
+ nonce: generateNonce(),
195
+ });
196
+
197
+ const signature = await signer.signMessage(
198
+ await crypto.subtle.digest("SHA-256", intentMessage)
199
+ );
200
+
201
+ // Execute swap
202
+ const swap = await api.executeSwap({
203
+ // ... swap parameters
204
+ signature: Buffer.from(signature).toString("hex"),
205
+ });
206
+ ```
207
+
208
+ ## Configuration
209
+
210
+ The SDK supports the following networks:
211
+
212
+ - `MAINNET` - Production network
213
+ - `REGTEST` - Regression test network
214
+
215
+ Each network has preconfigured endpoints for:
216
+
217
+ - AMM Gateway
218
+ - Mempool API
219
+ - Block Explorer
220
+ - SparkScan (when available)
221
+
222
+ ## FlashnetClient API Reference
223
+
224
+ The `FlashnetClient` provides a complete interface for AMM operations:
225
+
226
+ ### Initialization
227
+
228
+ ```typescript
229
+ const client = new FlashnetClient(wallet, {
230
+ autoAuthenticate: true, // Default: true
231
+ });
232
+
233
+ // Properties
234
+ client.wallet; // Access underlying SparkWallet
235
+ client.networkType; // Get network type
236
+ client.pubkey; // Get wallet public key
237
+ client.address; // Get Spark address
238
+ ```
239
+
240
+ ### Pool Operations
241
+
242
+ ```typescript
243
+ // List and search pools
244
+ await client.listPools({ limit: 10, sort: "tvlDesc" });
245
+
246
+ // Get pool details
247
+ await client.getPool(poolId);
248
+
249
+ // Get LP position
250
+ await client.getLpPosition(poolId);
251
+
252
+ // Create pools with automatic initial deposits
253
+ await client.createConstantProductPool({
254
+ assetATokenPublicKey: "token-a",
255
+ assetBTokenPublicKey: "token-b",
256
+ lpFeeRateBps: 30,
257
+ totalHostFeeRateBps: 10,
258
+ initialLiquidity: {
259
+ // Optional
260
+ assetAAmount: 1000000n,
261
+ assetBAmount: 5000n,
262
+ },
263
+ });
264
+
265
+ await client.createSingleSidedPool({
266
+ assetATokenPublicKey: "token-a",
267
+ assetBTokenPublicKey: BTC_ASSET_PUBKEY,
268
+ assetAInitialReserve: "1000000",
269
+ // ... other parameters
270
+ });
271
+ ```
272
+
273
+ ### Swap Operations
274
+
275
+ ```typescript
276
+ // Simulate first
277
+ const simulation = await client.simulateSwap({
278
+ poolId: "pool-id",
279
+ assetInTokenPublicKey: "token-in",
280
+ assetOutTokenPublicKey: "token-out",
281
+ amountIn: 1000000,
282
+ });
283
+
284
+ // Execute with automatic balance checking
285
+ await client.executeSwap({
286
+ poolId: "pool-id",
287
+ assetInTokenPublicKey: "token-in",
288
+ assetOutTokenPublicKey: "token-out",
289
+ amountIn: 1000000n,
290
+ minAmountOut: 950000n,
291
+ maxSlippageBps: 500,
292
+ });
293
+ ```
294
+
295
+ ### Liquidity Management
296
+
297
+ ```typescript
298
+ // Add liquidity
299
+ await client.addLiquidity({
300
+ poolId: "pool-id",
301
+ assetAAmount: 1000000n,
302
+ assetBAmount: 5000n,
303
+ });
304
+
305
+ // Remove liquidity
306
+ await client.removeLiquidity({
307
+ poolId: "pool-id",
308
+ lpTokensToRemove: "500000",
309
+ });
310
+ ```
311
+
312
+ ### Host Operations
313
+
314
+ ```typescript
315
+ // Register as host
316
+ await client.registerHost({
317
+ namespace: "my-exchange",
318
+ minFeeBps: 50,
319
+ feeRecipientPublicKey: "optional-different-pubkey",
320
+ });
321
+
322
+ await client.getHost("my-exchange");
323
+
324
+ await client.getPoolHostFees("my-exchange", "pool-id");
325
+
326
+ // Withdraw host fees
327
+ await client.withdrawHostFees({
328
+ lpIdentityPublicKey: "pool-id",
329
+ assetAAmount: "1000",
330
+ assetBAmount: "500",
331
+ });
332
+ ```
333
+
334
+ ## Modular Components Reference
335
+
336
+ ### 1. API Client
337
+
338
+ The API client handles all HTTP communication:
339
+
340
+ ```typescript
341
+ import { ApiClient } from "@flashnet/sdk";
342
+
343
+ const client = new ApiClient(config);
344
+
345
+ // Direct endpoints
346
+ const pools = await client.ammGet("/v1/pools");
347
+ const swapResult = await client.ammPost("/v1/swap", swapData);
348
+
349
+ // Typed API wrapper
350
+ const api = client.amm;
351
+ const pools = await api.listPools({ limit: 10 });
352
+ ```
353
+
354
+ ### 2. Authentication & Signing
355
+
356
+ Support for multiple signing methods:
357
+
358
+ ```typescript
359
+ // Using Spark Wallet
360
+ const authManager = new AuthManager(apiClient, pubkey, wallet);
361
+
362
+ // Using Custom Signer
363
+ class MyCustomSigner implements Signer {
364
+ async signMessage(message: Uint8Array): Promise<Uint8Array> {
365
+ // Your signing logic
366
+ return signature;
367
+ }
368
+ }
369
+
370
+ const signer = new MyCustomSigner();
371
+ const authManager = new AuthManager(apiClient, pubkey, signer);
372
+ await authManager.authenticate();
373
+ ```
374
+
375
+ ### 3. Intent Generation
376
+
377
+ Generate intent messages for operations:
378
+
379
+ ```typescript
380
+ import {
381
+ generatePoolSwapIntentMessage,
382
+ generateAddLiquidityIntentMessage,
383
+ generateConstantProductPoolInitializationIntentMessage,
384
+ generateNonce,
385
+ BTC_ASSET_PUBKEY,
386
+ } from "@flashnet/sdk";
387
+
388
+ // Swap intent
389
+ const swapIntent = generatePoolSwapIntentMessage({
390
+ userPublicKey: "userPubkey",
391
+ lpIdentityPublicKey: "poolPubkey",
392
+ assetASparkTransferId: "transferId",
393
+ // ... other parameters
394
+ nonce: generateNonce(),
395
+ });
396
+ ```
397
+
398
+ ### 4. Spark Address Utilities
399
+
400
+ Work with Spark addresses:
401
+
402
+ ```typescript
403
+ import {
404
+ encodeSparkAddress,
405
+ decodeSparkAddress,
406
+ isValidSparkAddress,
407
+ getNetworkFromAddress,
408
+ } from "@flashnet/sdk";
409
+
410
+ // Encode public key to address
411
+ const sparkAddress = encodeSparkAddress({
412
+ identityPublicKey: "02abc...",
413
+ network: "MAINNET",
414
+ });
415
+
416
+ // Detect network from address
417
+ const network = getNetworkFromAddress(sparkAddress);
418
+ ```
419
+
420
+ ### 5. Validation Utilities
421
+
422
+ Validate requests before sending:
423
+
424
+ ```typescript
425
+ import {
426
+ validateRequest,
427
+ commonValidationRules,
428
+ ValidationError,
429
+ } from "@flashnet/sdk";
430
+
431
+ try {
432
+ validateRequest(swapRequest, {
433
+ userPublicKey: commonValidationRules.publicKey,
434
+ amountIn: commonValidationRules.amount,
435
+ });
436
+ } catch (error) {
437
+ if (error instanceof ValidationError) {
438
+ console.error(`Invalid ${error.field}: ${error.reason}`);
439
+ }
440
+ }
441
+ ```
442
+
443
+ ## Error Handling
444
+
445
+ ```typescript
446
+ import { isFlashnetError } from "@flashnet/sdk";
447
+
448
+ try {
449
+ const result = await client.executeSwap(/* ... */);
450
+ } catch (error) {
451
+ if (isFlashnetError(error)) {
452
+ console.error(`API Error ${error.code}: ${error.msg}`);
453
+ }
454
+ // Handle other errors
455
+ }
456
+ ```
457
+
458
+ ## Types
459
+
460
+ The SDK exports all necessary TypeScript types:
461
+
462
+ ```typescript
463
+ import type {
464
+ NetworkType,
465
+ Pool,
466
+ Token,
467
+ SwapSimulationRequest,
468
+ SwapSimulationResponse,
469
+ ExecuteSwapRequest,
470
+ AddLiquidityRequest,
471
+ RemoveLiquidityRequest,
472
+ LpPosition,
473
+ Signer,
474
+ } from "@flashnet/sdk";
475
+ ```
476
+
477
+ ## License
478
+
479
+ MIT
@@ -0,0 +1,13 @@
1
+ export type * from "./src/types";
2
+ export type { RequestOptions } from "./src/api/client";
3
+ export { ApiClient } from "./src/api/client";
4
+ export { TypedAmmApi, isFlashnetError, isApiError, } from "./src/api/typed-endpoints";
5
+ export { validatePublicKey, validateSignature, validatePositiveAmount, validateBps, validateNamespace, validateRequest, ValidationError, commonValidationRules, constantProductPoolValidationRules, type ValidationRule, type ValidationRules, } from "./src/api/validation";
6
+ export * from "./src/config";
7
+ export { fromSmallestUnit, generateNonce, toSmallestUnit } from "./src/utils";
8
+ export { AuthManager } from "./src/utils/auth";
9
+ export { createWalletSigner } from "./src/utils/signer";
10
+ export { generateAddLiquidityIntentMessage, generatePoolConfirmInitialDepositIntentMessage, generatePoolInitializationIntentMessage, generateConstantProductPoolInitializationIntentMessage, generatePoolSwapIntentMessage, generateRemoveLiquidityIntentMessage, generateRegisterHostIntentMessage, generateWithdrawHostFeesIntentMessage, } from "./src/utils/intents";
11
+ export { convertSparkAddressToNetwork, decodeSparkAddress, encodeSparkAddress, getNetworkFromAddress, isValidPublicKey, isValidSparkAddress, looksLikePublicKey, type SparkAddressFormat, } from "./src/utils/spark-address";
12
+ export { FlashnetClient, type FlashnetClientOptions, type TokenBalance, type WalletBalance, } from "./src/client/FlashnetClient";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,mBAAmB,aAAa,CAAC;AACjC,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGvD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,eAAe,EACf,UAAU,GACX,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,kCAAkC,EAClC,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,sBAAsB,CAAC;AAG9B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,iCAAiC,EACjC,8CAA8C,EAC9C,uCAAuC,EACvC,sDAAsD,EACtD,6BAA6B,EAC7B,oCAAoC,EACpC,iCAAiC,EACjC,qCAAqC,GACtC,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,kBAAkB,GACxB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,aAAa,GACnB,MAAM,6BAA6B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ // Export API client and typed endpoints
2
+ export { ApiClient } from "./src/api/client";
3
+ export { TypedAmmApi, isFlashnetError, isApiError, } from "./src/api/typed-endpoints";
4
+ export { validatePublicKey, validateSignature, validatePositiveAmount, validateBps, validateNamespace, validateRequest, ValidationError, commonValidationRules, constantProductPoolValidationRules, } from "./src/api/validation";
5
+ // Export configuration
6
+ export * from "./src/config";
7
+ export { fromSmallestUnit, generateNonce, toSmallestUnit } from "./src/utils";
8
+ export { AuthManager } from "./src/utils/auth";
9
+ export { createWalletSigner } from "./src/utils/signer";
10
+ export { generateAddLiquidityIntentMessage, generatePoolConfirmInitialDepositIntentMessage, generatePoolInitializationIntentMessage, generateConstantProductPoolInitializationIntentMessage, generatePoolSwapIntentMessage, generateRemoveLiquidityIntentMessage, generateRegisterHostIntentMessage, generateWithdrawHostFeesIntentMessage, } from "./src/utils/intents";
11
+ // Export utilities
12
+ export { convertSparkAddressToNetwork, decodeSparkAddress, encodeSparkAddress, getNetworkFromAddress, isValidPublicKey, isValidSparkAddress, looksLikePublicKey, } from "./src/utils/spark-address";
13
+ // Export client
14
+ export { FlashnetClient, } from "./src/client/FlashnetClient";
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAIA,wCAAwC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,eAAe,EACf,UAAU,GACX,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,kCAAkC,GAGnC,MAAM,sBAAsB,CAAC;AAE9B,uBAAuB;AACvB,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,iCAAiC,EACjC,8CAA8C,EAC9C,uCAAuC,EACvC,sDAAsD,EACtD,6BAA6B,EAC7B,oCAAoC,EACpC,iCAAiC,EACjC,qCAAqC,GACtC,MAAM,qBAAqB,CAAC;AAE7B,mBAAmB;AACnB,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,GAEnB,MAAM,2BAA2B,CAAC;AAEnC,gBAAgB;AAChB,OAAO,EACL,cAAc,GAIf,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { NetworkConfig } from "../config";
2
+ import { TypedAmmApi } from "./typed-endpoints";
3
+ export interface RequestOptions {
4
+ headers?: Record<string, string>;
5
+ body?: any;
6
+ params?: Record<string, string | number>;
7
+ }
8
+ export declare class ApiClient {
9
+ private config;
10
+ private authToken?;
11
+ readonly amm: TypedAmmApi;
12
+ constructor(config: NetworkConfig);
13
+ setAuthToken(token: string): void;
14
+ private makeRequest;
15
+ ammPost<T>(path: string, body: any, options?: RequestOptions): Promise<T>;
16
+ ammGet<T>(path: string, options?: RequestOptions): Promise<T>;
17
+ mempoolGet<T>(path: string, options?: RequestOptions): Promise<T>;
18
+ sparkScanGet<T>(path: string, options?: RequestOptions): Promise<T>;
19
+ }
20
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;CAC1C;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,SAAgB,GAAG,EAAE,WAAW,CAAC;gBAErB,MAAM,EAAE,aAAa;IAKjC,YAAY,CAAC,KAAK,EAAE,MAAM;YAIZ,WAAW;IA0EnB,OAAO,CAAC,CAAC,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,GAAG,EACT,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC;IAOP,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IAS7D,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;IASjE,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;CAU1E"}
@@ -0,0 +1,85 @@
1
+ import { TypedAmmApi } from "./typed-endpoints";
2
+ export class ApiClient {
3
+ config;
4
+ authToken;
5
+ amm;
6
+ constructor(config) {
7
+ this.config = config;
8
+ this.amm = new TypedAmmApi(this);
9
+ }
10
+ setAuthToken(token) {
11
+ this.authToken = token;
12
+ }
13
+ async makeRequest(url, method, options) {
14
+ const headers = {
15
+ "Content-Type": "application/json",
16
+ ...options?.headers,
17
+ };
18
+ if (this.authToken) {
19
+ headers.Authorization = `Bearer ${this.authToken}`;
20
+ }
21
+ const requestOptions = {
22
+ method,
23
+ headers,
24
+ };
25
+ if (options?.body && method !== "GET") {
26
+ requestOptions.body = JSON.stringify(options.body);
27
+ }
28
+ // Add query parameters if provided
29
+ let finalUrl = url;
30
+ if (options?.params) {
31
+ const params = new URLSearchParams();
32
+ Object.entries(options.params).forEach(([key, value]) => {
33
+ params.append(key, value.toString());
34
+ });
35
+ finalUrl = `${url}?${params.toString()}`;
36
+ }
37
+ const response = await fetch(finalUrl, requestOptions);
38
+ if (!response.ok) {
39
+ const errorData = (await response.json().catch(() => null));
40
+ // Log detailed error info for debugging
41
+ if (response.status === 400 || response.status === 422) {
42
+ console.error(`\n❌ API Error (${response.status}):`);
43
+ console.error("URL:", finalUrl);
44
+ console.error("Method:", method);
45
+ if (options?.body) {
46
+ console.error("Request body:", JSON.stringify(options.body, null, 2));
47
+ }
48
+ if (errorData) {
49
+ console.error("Error response:", JSON.stringify(errorData, null, 2));
50
+ }
51
+ }
52
+ // Create error with additional properties
53
+ const error = new Error(errorData?.message ||
54
+ errorData?.msg ||
55
+ `HTTP error! status: ${response.status}`);
56
+ error.status = response.status;
57
+ error.response = { status: response.status, data: errorData };
58
+ error.request = { url: finalUrl, method, body: options?.body };
59
+ throw error;
60
+ }
61
+ return response.json();
62
+ }
63
+ // AMM Gateway endpoints
64
+ async ammPost(path, body, options) {
65
+ return this.makeRequest(`${this.config.ammGatewayUrl}${path}`, "POST", {
66
+ ...options,
67
+ body,
68
+ });
69
+ }
70
+ async ammGet(path, options) {
71
+ return this.makeRequest(`${this.config.ammGatewayUrl}${path}`, "GET", options);
72
+ }
73
+ // Mempool API endpoints
74
+ async mempoolGet(path, options) {
75
+ return this.makeRequest(`${this.config.mempoolApiUrl}${path}`, "GET", options);
76
+ }
77
+ // SparkScan API endpoints (if available)
78
+ async sparkScanGet(path, options) {
79
+ if (!this.config.sparkScanUrl) {
80
+ throw new Error("SparkScan URL not configured for this network");
81
+ }
82
+ return this.makeRequest(`${this.config.sparkScanUrl}${path}`, "GET", options);
83
+ }
84
+ }
85
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/api/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAShD,MAAM,OAAO,SAAS;IACZ,MAAM,CAAgB;IACtB,SAAS,CAAU;IACX,GAAG,CAAc;IAEjC,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,YAAY,CAAC,KAAa;QACxB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;IAEO,KAAK,CAAC,WAAW,CACvB,GAAW,EACX,MAAc,EACd,OAAwB;QAExB,MAAM,OAAO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;YAClC,GAAG,OAAO,EAAE,OAAO;SACpB,CAAC;QAEF,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,OAAO,CAAC,aAAa,GAAG,UAAU,IAAI,CAAC,SAAS,EAAE,CAAC;QACrD,CAAC;QAED,MAAM,cAAc,GAAgB;YAClC,MAAM;YACN,OAAO;SACR,CAAC;QAEF,IAAI,OAA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