@bitzy-app/bitzy-sdk 0.0.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.
@@ -0,0 +1,800 @@
1
+ import { Address, PublicClient } from 'viem';
2
+ export { Address, zeroAddress } from 'viem';
3
+ import BigNumber from 'bignumber.js';
4
+ export { default as BigNumber } from 'bignumber.js';
5
+
6
+ interface UseSwapV3RoutesAddressConfig {
7
+ /**
8
+ * Address of the Bitzy router contract
9
+ * Used for executing swap transactions
10
+ * @example "0xA5E0AE4e5103dc71cA290AA3654830442357A489"
11
+ */
12
+ routerAddress: Address;
13
+ /**
14
+ * Address of the Bitzy query contract
15
+ * Used for fetching swap routes and pricing data
16
+ * @example "0x5b5079587501Bd85d3CDf5bFDf299f4eaAe98c23"
17
+ */
18
+ bitzyQueryAddress: Address;
19
+ /**
20
+ * Address of the wrapped native token (e.g., pBTC on Botanix)
21
+ * Used for handling native token swaps
22
+ * @example "0x0D2437F93Fed6EA64Ef01cCde385FB1263910C56"
23
+ */
24
+ wrappedAddress: Address;
25
+ /**
26
+ * Address representing the native token (ETH/BTC)
27
+ * Standard address used across all networks for native tokens
28
+ * @example "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
29
+ */
30
+ nativeAddress: Address;
31
+ }
32
+ interface UseSwapV3RoutesConfig {
33
+ /**
34
+ * Base URL for the Bitzy API
35
+ * @default "https://api-public.bitzy.app"
36
+ * @example "https://api-public.bitzy.app"
37
+ */
38
+ apiBaseUrl?: string;
39
+ /**
40
+ * API key for authentication (optional)
41
+ * Used for premium features and rate limiting
42
+ * @example "your-api-key-here"
43
+ */
44
+ apiKey?: string;
45
+ /**
46
+ * Contract addresses configuration for the specific network
47
+ * Contains router, query, wrapped, and native token addresses
48
+ */
49
+ config?: UseSwapV3RoutesAddressConfig;
50
+ /**
51
+ * Default number of routes to split large swaps into
52
+ * Higher values provide better execution but increase gas costs
53
+ * @default 5
54
+ * @example 5
55
+ */
56
+ defaultPartCount?: number;
57
+ /**
58
+ * Request timeout in milliseconds
59
+ * @default 30000 (30 seconds)
60
+ * @example 30000
61
+ */
62
+ timeout?: number;
63
+ /**
64
+ * Additional HTTP headers to include with API requests
65
+ * @example { "authen-key": "token" }
66
+ */
67
+ headers?: Record<string, string>;
68
+ /**
69
+ * Interval in milliseconds for automatic route refresh
70
+ * Set to 0 to disable automatic refresh
71
+ * @default 10000 (10 seconds)
72
+ * @example 10000
73
+ */
74
+ refreshInterval?: number;
75
+ /**
76
+ * Viem PublicClient instance for blockchain interactions
77
+ * Used for contract calls and blockchain state queries
78
+ * @example publicClient from useAccount() hook
79
+ */
80
+ publicClient?: PublicClient;
81
+ /**
82
+ * Array of liquidity source types to include
83
+ * 1 = V2, 2 = V3
84
+ * @default [1, 2] (both V2 and V3)
85
+ * @example [2] (V3 only)
86
+ */
87
+ types?: number[];
88
+ /**
89
+ * Array of enabled liquidity sources
90
+ * 1 = BITZY, 2 = Other sources
91
+ * @default [1] (BITZY only)
92
+ * @example [1, 2] (BITZY and other sources)
93
+ */
94
+ enabledSources?: number[];
95
+ /**
96
+ * Override partCount calculation logic (offline mode only)
97
+ * - If provided, this value will be used instead of automatic calculation
98
+ * - **IGNORED when useOnlinePartCount is true** (best practice)
99
+ * - If not provided, uses intelligent address-based logic:
100
+ * - High-value tokens (BTC, ETH, USDC, USDT): partCount = 5 (better routing)
101
+ * - Low-value tokens (meme tokens, small caps): partCount = 1 (simpler routing)
102
+ *
103
+ * IMPORTANT EXCEPTIONS & CONCERNS:
104
+ *
105
+ * ## Pair Liquidity Impact:
106
+ * Even high-value tokens can cause issues in low-liquidity pairs:
107
+ *
108
+ * ### Problem Examples:
109
+ * - **BTC-X pair** with only $100 liquidity → Using 5 parts for $1000 swap = 50% impact per part
110
+ * - **USDC-X pair** with $100,000 liquidity → Using 5 parts for $1000 swap = 1% impact per part
111
+ *
112
+ * ### When to Override (offline mode only):
113
+ * ```typescript
114
+ * // Low liquidity pair - force single route
115
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
116
+ * ...config,
117
+ * useOnlinePartCount: false, // Disable online mode
118
+ * forcePartCount: 1, // Avoid splitting in low liquidity
119
+ * });
120
+ *
121
+ * // High liquidity pair - allow more routes
122
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
123
+ * ...config,
124
+ * useOnlinePartCount: false, // Disable online mode
125
+ * forcePartCount: 5, // Safe to split in high liquidity
126
+ * });
127
+ * ```
128
+ *
129
+ * ### Concerns to Consider:
130
+ * - **Slippage**: Too many parts in low liquidity = higher slippage
131
+ * - **Gas costs**: More routes = higher transaction costs
132
+ * - **Execution time**: More routes = longer execution
133
+ * - **Price impact**: Each part affects price, compounding impact
134
+ *
135
+ * ### Recommended Approach:
136
+ * 1. **Use useOnlinePartCount: true** for automatic pair liquidity detection
137
+ * 2. **Use forcePartCount** only when online mode is disabled
138
+ * 3. **Monitor slippage** and adjust accordingly
139
+ */
140
+ forcePartCount?: number;
141
+ /**
142
+ * Use online API to determine optimal partCount based on real pair liquidity
143
+ * - If true, calls API to get actual pair liquidity and calculates optimal partCount
144
+ * - If false or undefined, uses offline address-based logic
145
+ * - Falls back to offline logic if API call fails
146
+ * - Uses sensible defaults: 5% max impact, $10,000 min liquidity
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * // Use online API for accurate partCount calculation
151
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
152
+ * ...config,
153
+ * useOnlinePartCount: true, // Get real-time pair liquidity data
154
+ * });
155
+ * ```
156
+ */
157
+ useOnlinePartCount?: boolean;
158
+ }
159
+ type BN = BigNumber;
160
+
161
+ declare const ensureBigNumber: (value: any) => BigNumber;
162
+ declare const isBigNumber: (value: any) => value is BigNumber;
163
+ interface SwapV3AddressConfig extends UseSwapV3RoutesAddressConfig {
164
+ /**
165
+ * Gas limit for transactions
166
+ * @default BigInt(50_000_000_000)
167
+ * @example BigInt(50_000_000_000)
168
+ */
169
+ gasLimit?: bigint;
170
+ /**
171
+ * Gas price for transactions (optional)
172
+ * If not provided, uses network default
173
+ * @example BigInt(20_000_000_000) // 20 gwei
174
+ */
175
+ gasPrice?: bigint;
176
+ }
177
+ interface Token {
178
+ address: Address;
179
+ symbol: string;
180
+ name: string;
181
+ decimals: number;
182
+ logoURI?: string;
183
+ chainId?: number;
184
+ }
185
+ interface SwapRoute {
186
+ routerAddress: Address;
187
+ lpAddress: Address;
188
+ fromToken: Address;
189
+ toToken: Address;
190
+ from: Address;
191
+ to: Address;
192
+ part: string;
193
+ amountAfterFee: string;
194
+ dexInterface: number;
195
+ }
196
+ interface SwapResult {
197
+ routes: SwapRoute[][];
198
+ distributions: number[];
199
+ amountOutRoutes: BigNumber[];
200
+ amountOutBN: BigNumber;
201
+ amountInParts: BigNumber[];
202
+ isAmountOutError: boolean;
203
+ isWrap?: "wrap" | "unwrap";
204
+ }
205
+ interface SwapOptions {
206
+ amountIn: string;
207
+ srcToken: Token;
208
+ dstToken: Token;
209
+ chainId: number;
210
+ partCount?: number;
211
+ liquiditySources?: LiquiditySource[];
212
+ types?: number[];
213
+ enabledSources?: number[];
214
+ /**
215
+ * Force a specific partCount, overriding intelligent calculation
216
+ * - If provided, this value will be used instead of automatic calculation
217
+ * - If not provided, uses intelligent address-based logic:
218
+ * - High-value tokens (BTC, ETH, USDC, USDT): partCount = 5 (better routing)
219
+ * - Low-value tokens (meme tokens, small caps): partCount = 1 (simpler routing)
220
+ */
221
+ forcePartCount?: number;
222
+ }
223
+ interface LiquiditySource {
224
+ type: "V2" | "V3";
225
+ source: string;
226
+ enabled: boolean;
227
+ }
228
+ interface NetworkConfig {
229
+ routerAddress: Address;
230
+ bitzyQueryAddress: Address;
231
+ wrappedAddress: Address;
232
+ nativeAddress: Address;
233
+ }
234
+ interface PathV3Response {
235
+ data: {
236
+ hops: any[];
237
+ validPath: any[];
238
+ };
239
+ }
240
+ declare class SwapError extends Error {
241
+ code: string;
242
+ details?: any;
243
+ constructor(options: {
244
+ message: string;
245
+ code: string;
246
+ details?: any;
247
+ });
248
+ }
249
+ type ChainWrap<T> = {
250
+ [chainId: number]: T;
251
+ };
252
+ interface LiquiditySourcesConfig {
253
+ types: number[];
254
+ enabledSources: number[];
255
+ }
256
+ interface SDKConfig {
257
+ networks: Record<number, NetworkConfig>;
258
+ defaultPartCount: number;
259
+ apiBaseUrl?: string;
260
+ timeout?: number;
261
+ }
262
+
263
+ interface FetchSwapRouteConfig {
264
+ apiBaseUrl?: string;
265
+ networks?: Record<number, any>;
266
+ defaultPartCount?: number;
267
+ timeout?: number;
268
+ headers?: Record<string, string>;
269
+ /**
270
+ * Force a specific partCount, overriding intelligent calculation
271
+ * - If provided, this value will be used instead of automatic calculation
272
+ * - If not provided, uses intelligent address-based logic:
273
+ * - High-value tokens (BTC, ETH, USDC, USDT): partCount = 5 (better routing)
274
+ * - Low-value tokens (meme tokens, small caps): partCount = 1 (simpler routing)
275
+ */
276
+ forcePartCount?: number;
277
+ }
278
+ /**
279
+ * Common function to fetch swap routes
280
+ * Can be used in any JavaScript/TypeScript environment
281
+ */
282
+ declare function fetchSwapRoute(options: SwapOptions, config?: FetchSwapRouteConfig): Promise<SwapResult>;
283
+ /**
284
+ * Batch fetch multiple swap routes
285
+ */
286
+ declare function fetchBatchSwapRoutes(swaps: Array<{
287
+ options: SwapOptions;
288
+ config: FetchSwapRouteConfig;
289
+ }>): Promise<Array<{
290
+ success: boolean;
291
+ data?: SwapResult;
292
+ error?: string;
293
+ }>>;
294
+ /**
295
+ * Simple quote function
296
+ */
297
+ declare function getSwapQuote(srcToken: Token, dstToken: Token, amountIn: string, chainId: number, config?: FetchSwapRouteConfig): Promise<{
298
+ amountOut: string;
299
+ routes: number;
300
+ }>;
301
+ interface SimplifiedSwapOptions {
302
+ amountIn: string;
303
+ srcToken: Token;
304
+ dstToken: Token;
305
+ chainId: number;
306
+ partCount?: number;
307
+ publicClient?: PublicClient;
308
+ }
309
+ /**
310
+ * Simplified swap route fetching for 3rd party users
311
+ * Automatically uses network-specific liquidity sources
312
+ */
313
+ declare function fetchSwapRouteSimple(options: SimplifiedSwapOptions, config?: FetchSwapRouteConfig): Promise<SwapResult>;
314
+
315
+ interface UseSwapV3RoutesReturn {
316
+ routes: any[][];
317
+ distributions: number[];
318
+ amountOutRoutes: any[];
319
+ amountOutBN: BigNumber;
320
+ amountInParts: any[];
321
+ fetchRoute: () => Promise<void>;
322
+ isLoading: boolean;
323
+ isAmountOutError: boolean;
324
+ isFirstFetch: boolean;
325
+ isWrap?: "wrap" | "unwrap";
326
+ error: string | null;
327
+ clearError: () => void;
328
+ }
329
+ /**
330
+ * Hot React Hook for Bitzy Swap V3 Routes
331
+ *
332
+ * Provides real-time swap route finding with automatic updates and intelligent routing optimization.
333
+ *
334
+ * ## Key Features:
335
+ *
336
+ * ### Intelligent partCount Logic:
337
+ * - **High-value tokens** (BTC, ETH, USDC, USDT): Uses `partCount = 5` for optimal execution
338
+ * - **Low-value tokens** (meme tokens, small caps): Uses `partCount = 1` for simplicity
339
+ *
340
+ * ### Benefits:
341
+ * - **BTC/ETH swaps**: Use 5 routes for optimal execution and better pricing
342
+ * - **Meme token swaps**: Use 1 route for simplicity and lower gas costs
343
+ * - **Stablecoin swaps**: Use 5 routes for better price discovery
344
+ * - **Easy to extend**: Just add more addresses to the high-value list
345
+ *
346
+ * ### Important Exceptions:
347
+ * **Pair liquidity matters more than token value!**
348
+ * - BTC-X pair with $100 liquidity → 5 parts for $1000 = 50% impact per part
349
+ * - USDC-X pair with $100,000 liquidity → 5 parts for $1000 = 1% impact per part
350
+ *
351
+ * ### User Control:
352
+ * - **Online mode**: Use `useOnlinePartCount: true` for automatic pair liquidity detection
353
+ * - **Offline mode**: Override with `forcePartCount` parameter (ignored when online mode is enabled)
354
+ * - Customize `defaultPartCount` for high-value tokens
355
+ * - **Best practice**: Use online mode for accurate results, offline mode for speed
356
+ *
357
+ * ## Usage Examples:
358
+ *
359
+ * ```typescript
360
+ * // Minimal usage with defaults
361
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId);
362
+ * // Uses: apiBaseUrl from DEFAULT_API_BASE_URL, apiKey from NEXT_PUBLIC_BITZY_API_KEY env var or fallback
363
+ *
364
+ * // With custom API URL
365
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
366
+ * apiBaseUrl: "https://api-public.bitzy.app",
367
+ * });
368
+ *
369
+ * // With custom API key
370
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
371
+ * apiKey: "your-custom-api-key",
372
+ * });
373
+ *
374
+ * // With custom liquidity sources
375
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
376
+ * apiBaseUrl: "https://api-public.bitzy.app",
377
+ * types: [2], // Only V3
378
+ * enabledSources: [1], // Only BITZY
379
+ * });
380
+ *
381
+ * // With custom address config
382
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
383
+ * apiBaseUrl: "https://api-public.bitzy.app",
384
+ * config: addressConfig,
385
+ * });
386
+ *
387
+ * // Force specific partCount
388
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
389
+ * apiBaseUrl: "https://api-public.bitzy.app",
390
+ * config: addressConfig,
391
+ * forcePartCount: 3, // Always use 3 routes
392
+ * });
393
+ *
394
+ * // Custom default for high-value tokens
395
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
396
+ * apiBaseUrl: "https://api-public.bitzy.app",
397
+ * config: addressConfig,
398
+ * defaultPartCount: 7, // High-value tokens use 7 routes instead of 5
399
+ * });
400
+ *
401
+ * // CRITICAL: Check pair liquidity first!
402
+ * // Low liquidity pair - force single route
403
+ * const lowLiquidityResult = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
404
+ * apiBaseUrl: "https://api-public.bitzy.app",
405
+ * config: addressConfig,
406
+ * forcePartCount: 1, // Avoid splitting in low liquidity pairs
407
+ * });
408
+ *
409
+ * // High liquidity pair - safe to use multiple routes
410
+ * const highLiquidityResult = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
411
+ * apiBaseUrl: "https://api-public.bitzy.app",
412
+ * config: addressConfig,
413
+ * forcePartCount: 5, // Safe to split in high liquidity pairs
414
+ * });
415
+ * ```
416
+ */
417
+ declare const useSwapV3Routes: (srcToken: Token | undefined | null, dstToken: Token | undefined | null, amountIn: string, chainId: number, config?: UseSwapV3RoutesConfig) => UseSwapV3RoutesReturn;
418
+
419
+ interface APIClientConfig {
420
+ baseUrl: string;
421
+ timeout: number;
422
+ headers?: Record<string, string>;
423
+ }
424
+ declare class APIClient {
425
+ private static instance;
426
+ private config;
427
+ private constructor();
428
+ /**
429
+ * Get singleton instance of APIClient
430
+ * Initializes once with API key and reuses for all requests
431
+ *
432
+ * API Key Priority:
433
+ * 1. Custom headers (if "authen-key" provided in config.headers)
434
+ * 2. NEXT_PUBLIC_BITZY_API_KEY environment variable
435
+ * 3. No authentication (if neither provided)
436
+ */
437
+ static getInstance(config: APIClientConfig): APIClient;
438
+ /**
439
+ * Reset singleton instance (useful for testing or API key changes)
440
+ */
441
+ static resetInstance(): void;
442
+ /**
443
+ * Make HTTP request with timeout and error handling
444
+ */
445
+ private request;
446
+ /**
447
+ * Get V3 path for swap routing
448
+ */
449
+ getPathV3(srcToken: Token, dstToken: Token, amountIn: string, types: number[], enabledSources: number[]): Promise<PathV3Response>;
450
+ /**
451
+ * Get asset minimum partCount from SDK API
452
+ * Returns minimum amounts for tokens to use multiple routes
453
+ */
454
+ getAssetMinimum(): Promise<any>;
455
+ /**
456
+ * Build query string from parameters
457
+ */
458
+ private buildQueryString;
459
+ }
460
+
461
+ interface SwapV3ServiceConfig {
462
+ config: SwapV3AddressConfig;
463
+ defaultPartCount: number;
464
+ apiClient: APIClient;
465
+ publicClient?: PublicClient;
466
+ }
467
+ declare class SwapV3Service {
468
+ private config;
469
+ constructor(config: SwapV3ServiceConfig);
470
+ /**
471
+ * Fetch swap routes for V3 swaps
472
+ * This is the core function extracted from the React hook
473
+ *
474
+ * ## Intelligent Routing:
475
+ * - **High-value tokens** (BTC, ETH, USDC, USDT): Uses `partCount = 5` for optimal execution
476
+ * - **Low-value tokens** (meme tokens, small caps): Uses `partCount = 1` for simplicity
477
+ *
478
+ * ## Benefits:
479
+ * - **BTC/ETH swaps**: Use 5 routes for optimal execution and better pricing
480
+ * - **Meme token swaps**: Use 1 route for simplicity and lower gas costs
481
+ * - **Stablecoin swaps**: Use 5 routes for better price discovery
482
+ * - **Easy to extend**: Just add more addresses to the high-value list
483
+ *
484
+ * ## CRITICAL EXCEPTION - Pair Liquidity Impact:
485
+ * **Pair liquidity matters more than token value!**
486
+ *
487
+ * ### Problem Examples:
488
+ * - **BTC-X pair** with only $100 liquidity → Using 5 parts for $1000 swap = 50% impact per part
489
+ * - **USDC-X pair** with $100,000 liquidity → Using 5 parts for $1000 swap = 1% impact per part
490
+ *
491
+ * ### When to Override:
492
+ * - Use `forcePartCount: 1` for low liquidity pairs
493
+ * - Use `forcePartCount: 5` for high liquidity pairs
494
+ * - Always check pair liquidity before deciding partCount
495
+ *
496
+ * ### Concerns:
497
+ * - **Slippage**: Too many parts in low liquidity = higher slippage
498
+ * - **Gas costs**: More routes = higher transaction costs
499
+ * - **Price impact**: Each part affects price, compounding impact
500
+ */
501
+ fetchRoute(options: SwapOptions): Promise<SwapResult>;
502
+ /**
503
+ * Get supported networks
504
+ */
505
+ getSupportedNetworks(): number[];
506
+ /**
507
+ * Get network configuration
508
+ */
509
+ getNetworkConfig(chainId: number): SwapV3AddressConfig | undefined;
510
+ /**
511
+ * Get partCount based on token pair addresses using utility function
512
+ * @param srcToken - The source token
513
+ * @param dstToken - The destination token
514
+ * @param chainId - The chain ID to get network-specific tokens
515
+ * @param defaultPartCount - Default partCount for high-value pairs
516
+ * @returns partCount: 5 for high-value pairs, 1 for others
517
+ */
518
+ private getPartCount;
519
+ }
520
+
521
+ declare const DEX_INTERFACE: {
522
+ readonly V2: 0;
523
+ readonly V3: 1;
524
+ };
525
+ declare const USER_TARGET: Address;
526
+ declare const ROUTER_TARGET: Address;
527
+ declare const DEFAULT_PART_COUNT = 5;
528
+ declare const DEFAULT_TIMEOUT = 30000;
529
+ declare const DEX_ROUTERS: ChainWrap<Record<string, Address>>;
530
+ declare const CONTRACT_ADDRESSES: ChainWrap<{
531
+ factoryAddress: Address;
532
+ v3FactoryAddress: Address;
533
+ v3PositionManagerAddress: Address;
534
+ v3WalletHelperAddress: Address;
535
+ routerAddress: Address;
536
+ aggregatorAddress: Address;
537
+ otcAddress: Address;
538
+ memeTokenGenerator: Address;
539
+ bitzyQueryAddress: Address;
540
+ wrappedAddress: Address;
541
+ nativeAddress: Address;
542
+ gasLimit: bigint;
543
+ }>;
544
+ declare const LIQUIDITY_SOURCES: ChainWrap<LiquiditySourcesConfig>;
545
+ declare const getLiquiditySources: (chainId: number) => LiquiditySourcesConfig;
546
+ declare const getContractAddresses: (chainId: number) => {
547
+ factoryAddress: Address;
548
+ v3FactoryAddress: Address;
549
+ v3PositionManagerAddress: Address;
550
+ v3WalletHelperAddress: Address;
551
+ routerAddress: Address;
552
+ aggregatorAddress: Address;
553
+ otcAddress: Address;
554
+ memeTokenGenerator: Address;
555
+ bitzyQueryAddress: Address;
556
+ wrappedAddress: Address;
557
+ nativeAddress: Address;
558
+ gasLimit: bigint;
559
+ };
560
+ declare const getDexRouters: (chainId: number) => Record<string, `0x${string}`>;
561
+ declare const DEFAULT_NETWORKS: ChainWrap<{
562
+ factoryAddress: Address;
563
+ v3FactoryAddress: Address;
564
+ v3PositionManagerAddress: Address;
565
+ v3WalletHelperAddress: Address;
566
+ routerAddress: Address;
567
+ aggregatorAddress: Address;
568
+ otcAddress: Address;
569
+ memeTokenGenerator: Address;
570
+ bitzyQueryAddress: Address;
571
+ wrappedAddress: Address;
572
+ nativeAddress: Address;
573
+ gasLimit: bigint;
574
+ }>;
575
+ declare const DEX_ROUTER: Record<string, `0x${string}`>;
576
+ declare const API_ENDPOINTS: {
577
+ readonly PATH_V3: "/api/sdk/bestpath/split";
578
+ readonly ASSET_MINIMUM: "/api/sdk/asset/minimum";
579
+ };
580
+ declare const ERROR_CODES: {
581
+ readonly INVALID_TOKENS: "INVALID_TOKENS";
582
+ readonly INVALID_AMOUNT: "INVALID_AMOUNT";
583
+ readonly NETWORK_NOT_SUPPORTED: "NETWORK_NOT_SUPPORTED";
584
+ readonly API_ERROR: "API_ERROR";
585
+ readonly QUERY_ERROR: "QUERY_ERROR";
586
+ readonly INSUFFICIENT_LIQUIDITY: "INSUFFICIENT_LIQUIDITY";
587
+ };
588
+
589
+ declare const BITZY_QUERY_ABI: readonly [{
590
+ readonly inputs: readonly [{
591
+ readonly internalType: "uint256";
592
+ readonly name: "srcAmount";
593
+ readonly type: "uint256";
594
+ }, {
595
+ readonly internalType: "bytes";
596
+ readonly name: "encodedRoutes";
597
+ readonly type: "bytes";
598
+ }, {
599
+ readonly internalType: "uint256";
600
+ readonly name: "parts";
601
+ readonly type: "uint256";
602
+ }];
603
+ readonly name: "splitQuery";
604
+ readonly outputs: readonly [{
605
+ readonly components: readonly [{
606
+ readonly internalType: "uint256";
607
+ readonly name: "amountOut";
608
+ readonly type: "uint256";
609
+ }, {
610
+ readonly internalType: "uint256";
611
+ readonly name: "bestIndex";
612
+ readonly type: "uint256";
613
+ }];
614
+ readonly internalType: "struct BitzyQueryV2.OneRoute";
615
+ readonly name: "";
616
+ readonly type: "tuple";
617
+ }, {
618
+ readonly components: readonly [{
619
+ readonly internalType: "uint256[]";
620
+ readonly name: "distribution";
621
+ readonly type: "uint256[]";
622
+ }, {
623
+ readonly internalType: "uint256";
624
+ readonly name: "amountOut";
625
+ readonly type: "uint256";
626
+ }];
627
+ readonly internalType: "struct BitzyQueryV2.SplitRoute";
628
+ readonly name: "";
629
+ readonly type: "tuple";
630
+ }];
631
+ readonly stateMutability: "nonpayable";
632
+ readonly type: "function";
633
+ }];
634
+
635
+ /**
636
+ * Convert token amount from human readable format to wei
637
+ * @param amount - Human readable amount (e.g., "1.5")
638
+ * @param decimals - Token decimals
639
+ * @returns BigNumber representation in wei
640
+ */
641
+ declare function fromTokenAmount(amount: string, decimals: number): BigNumber;
642
+ /**
643
+ * Convert token amount from wei to human readable format
644
+ * @param amount - Amount in wei
645
+ * @param decimals - Token decimals
646
+ * @returns Human readable amount string
647
+ */
648
+ declare function toTokenAmount(amount: BigNumber | string, decimals: number): string;
649
+ /**
650
+ * Check if a token is native (ETH, BNB, etc.)
651
+ * @param token - Token to check
652
+ * @param nativeAddress - Native token address for the network
653
+ * @returns boolean
654
+ */
655
+ declare function isNativeToken(token: Token, nativeAddress: Address): boolean;
656
+ /**
657
+ * Check if a token is wrapped (WETH, WBNB, etc.)
658
+ * @param token - Token to check
659
+ * @param wrappedAddress - Wrapped token address for the network
660
+ * @returns boolean
661
+ */
662
+ declare function isWrappedToken(token: Token, wrappedAddress: Address): boolean;
663
+ /**
664
+ * Validate token addresses
665
+ * @param srcToken - Source token
666
+ * @param dstToken - Destination token
667
+ * @returns boolean
668
+ */
669
+ declare function validateTokens(srcToken: Token, dstToken: Token): boolean;
670
+ /**
671
+ * Validate amount input
672
+ * @param amount - Amount to validate
673
+ * @returns boolean
674
+ */
675
+ declare function validateAmount(amount: string): boolean;
676
+ /**
677
+ * Calculate optimal part count of a route based on amount and price
678
+ * @param amount - Input amount
679
+ * @param price - Token price in USD
680
+ * @param partCount - Default part count of a route
681
+ * @returns number
682
+ */
683
+ declare function calculatePartCount(amount: string, price: number, partCount?: number): number;
684
+ /**
685
+ * Format error message
686
+ * @param error - Error object or string
687
+ * @returns Formatted error string
688
+ */
689
+ declare function formatError(error: any): string;
690
+ /**
691
+ * Debounce function
692
+ * @param func - Function to debounce
693
+ * @param wait - Wait time in milliseconds
694
+ * @returns Debounced function with cancel method
695
+ */
696
+ declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number): ((...args: Parameters<T>) => void) & {
697
+ cancel: () => void;
698
+ };
699
+
700
+ /**
701
+ * Clear the minimum amounts cache
702
+ * Useful for testing or when you need fresh data immediately
703
+ */
704
+ declare function clearMinimumAmountsCache(): void;
705
+ /**
706
+ * High-value tokens that benefit from multi-route optimization
707
+ * These tokens typically have high liquidity and benefit from route splitting
708
+ * Network-specific token addresses using ChainWrap pattern
709
+ */
710
+ declare const HIGH_VALUE_TOKENS: ChainWrap<string[]>;
711
+ /**
712
+ * Check if a token is considered high-value based on its address and chain
713
+ * @param token - The token to check
714
+ * @param chainId - The chain ID to get network-specific tokens
715
+ * @returns true if the token is high-value, false otherwise
716
+ */
717
+ declare function isHighValueToken(token: Token | undefined | null, chainId: number): boolean;
718
+ /**
719
+ * Get partCount based on token pair addresses (offline logic)
720
+ * This function uses hardcoded address-based logic to determine optimal partCount
721
+ * Considers both tokens in the pair for better decision making
722
+ *
723
+ * IMPORTANT: This is a simplified approach that doesn't consider actual pair liquidity!
724
+ * For more accurate results, use getPartCountOnline() which checks actual pair liquidity.
725
+ *
726
+ * @param srcToken - The source token
727
+ * @param dstToken - The destination token
728
+ * @param chainId - The chain ID to get network-specific tokens
729
+ * @param defaultPartCount - Default partCount for high-value pairs (default: 5)
730
+ * @returns partCount: 5 for high-value pairs, 1 for others
731
+ *
732
+ * @example
733
+ * ```typescript
734
+ * // High-value pair (BTC-USDC) → returns 5
735
+ * const highValuePartCount = getPartCountOffline(btcToken, usdcToken, 3637, 5);
736
+ *
737
+ * // Low-value pair (BTC-MEME) → returns 1
738
+ * const lowValuePartCount = getPartCountOffline(btcToken, memeToken, 3637, 5);
739
+ * ```
740
+ */
741
+ declare function getPartCountOffline(srcToken: Token | undefined | null, dstToken: Token | undefined | null, chainId: number, defaultPartCount?: number): number;
742
+ /**
743
+ * Get partCount using online API data (minimum amount-based)
744
+ * Checks if the swap amount meets the minimum threshold for multi-route optimization
745
+ *
746
+ * @param srcToken - Source token
747
+ * @param dstToken - Destination token
748
+ * @param amountIn - Input amount
749
+ * @param chainId - Chain ID
750
+ * @param apiBaseUrl - API base URL
751
+ * @param apiKey - Optional API key
752
+ * @returns Promise<number> - partCount (5 if amount >= minimum for both tokens, otherwise fallback)
753
+ */
754
+ declare function getPartCountOnline(srcToken: Token, dstToken: Token, amountIn: string, chainId: number, apiBaseUrl: string, apiKey?: string, fallbackPartCount?: number): Promise<number>;
755
+ /**
756
+ * Get partCount with fallback strategy
757
+ * Tries online API first, falls back to offline logic if API fails
758
+ * Uses sensible defaults: 5% max impact, $10,000 min liquidity
759
+ *
760
+ * @param srcToken - The source token
761
+ * @param dstToken - The destination token
762
+ * @param amountIn - The swap amount
763
+ * @param chainId - The chain ID
764
+ * @param apiBaseUrl - The API base URL
765
+ * @param fallbackPartCount - PartCount to use if API fails (default: 5)
766
+ * @returns Promise<number> - Optimal partCount
767
+ *
768
+ * @example
769
+ * ```typescript
770
+ * // Try online first, fallback to offline
771
+ * const partCount = await getPartCountWithFallback(
772
+ * srcToken,
773
+ * dstToken,
774
+ * amountIn,
775
+ * chainId,
776
+ * apiBaseUrl,
777
+ * 5 // fallback partCount
778
+ * );
779
+ * ```
780
+ */
781
+ declare function getPartCountWithFallback(srcToken: Token, dstToken: Token, amountIn: string, chainId: number, apiBaseUrl: string, fallbackPartCount?: number, apiKey?: string): Promise<number>;
782
+ /**
783
+ * Calculate price impact for a given swap
784
+ * @param swapAmount - The swap amount in USD
785
+ * @param pairLiquidity - The pair liquidity in USD
786
+ * @param partCount - The number of parts to split the swap
787
+ * @returns The price impact percentage
788
+ */
789
+ declare function calculatePriceImpact(swapAmount: number, pairLiquidity: number, partCount: number): number;
790
+ /**
791
+ * Determine optimal partCount based on price impact thresholds
792
+ * @param swapAmount - The swap amount in USD
793
+ * @param pairLiquidity - The pair liquidity in USD
794
+ * @param maxImpactThreshold - Maximum acceptable impact per part (default: 5%)
795
+ * @returns Optimal partCount (1 or 5)
796
+ */
797
+ declare function getOptimalPartCount(swapAmount: number, pairLiquidity: number, maxImpactThreshold?: number): number;
798
+
799
+ export { APIClient, API_ENDPOINTS, BITZY_QUERY_ABI, CONTRACT_ADDRESSES, DEFAULT_NETWORKS, DEFAULT_PART_COUNT, DEFAULT_TIMEOUT, DEX_INTERFACE, DEX_ROUTER, DEX_ROUTERS, ERROR_CODES, HIGH_VALUE_TOKENS, LIQUIDITY_SOURCES, ROUTER_TARGET, SwapError, SwapV3Service, USER_TARGET, calculatePartCount, calculatePriceImpact, clearMinimumAmountsCache, debounce, ensureBigNumber, fetchBatchSwapRoutes, fetchSwapRoute, fetchSwapRouteSimple, formatError, fromTokenAmount, getContractAddresses, getDexRouters, getLiquiditySources, getOptimalPartCount, getPartCountOffline, getPartCountOnline, getPartCountWithFallback, getSwapQuote, fetchSwapRoute as getSwapRoute, isBigNumber, isHighValueToken, isNativeToken, isWrappedToken, toTokenAmount, useSwapV3Routes as useSwapRoutes, useSwapV3Routes, validateAmount, validateTokens };
800
+ export type { APIClientConfig, BN, ChainWrap, FetchSwapRouteConfig, LiquiditySource, LiquiditySourcesConfig, NetworkConfig, PathV3Response, SDKConfig, SwapOptions, SwapResult, SwapRoute, SwapV3AddressConfig, SwapV3ServiceConfig, Token, UseSwapV3RoutesAddressConfig, UseSwapV3RoutesConfig, UseSwapV3RoutesReturn };