@bitzy-app/bitzy-sdk 0.0.6 → 0.1.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 +26 -0
- package/README.md +114 -47
- package/dist/api/Client.d.ts +2 -0
- package/dist/api/Client.d.ts.map +1 -1
- package/dist/common/FetchSwapRoute.d.ts +7 -0
- package/dist/common/FetchSwapRoute.d.ts.map +1 -1
- package/dist/constants/index.d.ts +18 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/index.d.ts +14 -0
- package/dist/index.esm.js +1 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/services/SwapV3Service.d.ts +5 -0
- package/dist/services/SwapV3Service.d.ts.map +1 -1
- package/package.json +10 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
## [0.1.1](https://github.com/bitzy-app/bitzy-sdk/compare/v0.1.0...v0.1.1) (2026-01-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# [0.1.0](https://github.com/bitzy-app/bitzy-sdk/compare/v0.0.8...v0.1.0) (2026-01-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* build setup ([53a9fed](https://github.com/bitzy-app/bitzy-sdk/commit/53a9fed4774a36c8d5f14d2699873c48d2daae68))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.0.8](https://github.com/bitzy-app/bitzy-sdk/compare/v0.0.7...v0.0.8) (2026-01-15)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* add automatic publicClient creation and RPC configuration ([4376ec3](https://github.com/bitzy-app/bitzy-sdk/commit/4376ec33161e18133126ea49835bcb4f19200a57))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## [0.0.7](https://github.com/bitzy-app/bitzy-sdk/compare/v0.0.6...v0.0.7) (2025-09-17)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
1
27
|
## [0.0.6](https://github.com/bitzy-app/bitzy-sdk/compare/v0.0.5...v0.0.6) (2025-09-08)
|
|
2
28
|
|
|
3
29
|
|
package/README.md
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
# Bitzy
|
|
1
|
+
# Bitzy Aggregator SDK - Multi-DEX Route Aggregation
|
|
2
2
|
|
|
3
|
-
A comprehensive SDK for
|
|
3
|
+
A comprehensive SDK for aggregating swap routes across multiple decentralized exchanges and executing optimal swaps. Provides both **common functions** for any environment and **React hooks** for frontend applications with intelligent route aggregation.
|
|
4
4
|
|
|
5
5
|
## **What This Package Provides**
|
|
6
6
|
|
|
7
|
+
- **Multi-DEX Aggregation** - Automatically finds the best routes across multiple decentralized exchanges
|
|
7
8
|
- **Common Functions** - Work in Node.js, browser, or any JavaScript environment
|
|
8
9
|
- **React Hooks** - Hot reloading with automatic updates and error handling
|
|
9
10
|
- **TypeScript Support** - Full type safety throughout
|
|
10
|
-
- **Intelligent
|
|
11
|
+
- **Intelligent Route Optimization** - Automatic aggregation based on token characteristics and liquidity
|
|
11
12
|
- **Multiple Networks** - Support for Botanix Mainnet and Testnet
|
|
13
|
+
- **Split Routing** - Distributes large swaps across multiple routes for optimal execution
|
|
14
|
+
|
|
15
|
+
## **Current Support Notice**
|
|
16
|
+
|
|
17
|
+
**Currently supports Bitzy V2 and Bitzy V3 liquidity sources only.**
|
|
18
|
+
|
|
19
|
+
This aggregator SDK begins with Bitzy's own DEX implementations. **Integration with additional external DEXs is planned for very soon.**
|
|
20
|
+
|
|
12
21
|
|
|
13
22
|
## **Quick Start**
|
|
14
23
|
|
|
@@ -24,7 +33,7 @@ pnpm add @bitzy-app/bitzy-sdk
|
|
|
24
33
|
|
|
25
34
|
## **1. Using Functions**
|
|
26
35
|
|
|
27
|
-
### **1.1 `fetchSwapRoute()` - Main Route
|
|
36
|
+
### **1.1 `fetchSwapRoute()` - Main Route Aggregation Function**
|
|
28
37
|
|
|
29
38
|
```typescript
|
|
30
39
|
import { fetchSwapRoute } from '@bitzy-app/bitzy-sdk';
|
|
@@ -54,7 +63,57 @@ console.log('Amount out:', result.amountOutBN.toFixed());
|
|
|
54
63
|
console.log('Distributions:', result.distributions);
|
|
55
64
|
```
|
|
56
65
|
|
|
57
|
-
|
|
66
|
+
**With Custom PublicClient (Optional):**
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { fetchSwapRoute } from '@bitzy-app/bitzy-sdk';
|
|
70
|
+
import { createPublicClient, http, defineChain } from 'viem';
|
|
71
|
+
|
|
72
|
+
// Create your own PublicClient (e.g., from wagmi, or custom RPC)
|
|
73
|
+
const publicClient = createPublicClient({
|
|
74
|
+
chain: defineChain({
|
|
75
|
+
id: 3637,
|
|
76
|
+
name: 'Botanix Mainnet',
|
|
77
|
+
network: 'botanix-mainnet',
|
|
78
|
+
nativeCurrency: {
|
|
79
|
+
name: 'Bitcoin',
|
|
80
|
+
symbol: 'BTC',
|
|
81
|
+
decimals: 18,
|
|
82
|
+
},
|
|
83
|
+
rpcUrls: {
|
|
84
|
+
default: { http: ['https://rpc.botanixlabs.com'] },
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
transport: http(),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Use your custom PublicClient for better performance and connection reuse
|
|
91
|
+
const result = await fetchSwapRoute(
|
|
92
|
+
{
|
|
93
|
+
amountIn: '1.5',
|
|
94
|
+
srcToken: btcToken,
|
|
95
|
+
dstToken: usdcToken,
|
|
96
|
+
chainId: 3637,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
publicClient: publicClient, // Optional: inject your own client
|
|
100
|
+
headers: {
|
|
101
|
+
'authen-key': 'your-api-key', // Optional: API key for authentication
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Note:** If you don't provide `publicClient`, the SDK will automatically create one using default RPC endpoints:
|
|
108
|
+
- **Botanix Mainnet (3637)**: `https://rpc.botanixlabs.com`
|
|
109
|
+
- **Botanix Testnet (3636)**: `https://node.botanixlabs.dev`
|
|
110
|
+
|
|
111
|
+
Injecting your own client is useful when:
|
|
112
|
+
- You already have a `PublicClient` instance (e.g., from wagmi's `useAccount()`)
|
|
113
|
+
- You want to reuse connections for better performance
|
|
114
|
+
- You need to use a custom RPC endpoint
|
|
115
|
+
|
|
116
|
+
### **1.2 `fetchBatchSwapRoutes()` - Batch Route Aggregation**
|
|
58
117
|
|
|
59
118
|
```typescript
|
|
60
119
|
import { fetchBatchSwapRoutes } from '@bitzy-app/bitzy-sdk';
|
|
@@ -91,7 +150,7 @@ results.forEach((result, index) => {
|
|
|
91
150
|
});
|
|
92
151
|
```
|
|
93
152
|
|
|
94
|
-
### **1.3 `getSwapQuote()` -
|
|
153
|
+
### **1.3 `getSwapQuote()` - Aggregated Price Quote**
|
|
95
154
|
|
|
96
155
|
```typescript
|
|
97
156
|
import { getSwapQuote } from '@bitzy-app/bitzy-sdk';
|
|
@@ -109,7 +168,7 @@ console.log('Amount out:', quote.amountOut);
|
|
|
109
168
|
console.log('Route count:', quote.routes);
|
|
110
169
|
```
|
|
111
170
|
|
|
112
|
-
### **1.4 `fetchSwapRouteSimple()` -
|
|
171
|
+
### **1.4 `fetchSwapRouteSimple()` - Simple Aggregation**
|
|
113
172
|
|
|
114
173
|
```typescript
|
|
115
174
|
import { fetchSwapRouteSimple } from '@bitzy-app/bitzy-sdk';
|
|
@@ -128,7 +187,7 @@ console.log('Best route:', result.routes[0]);
|
|
|
128
187
|
|
|
129
188
|
## **2. Using React Hooks**
|
|
130
189
|
|
|
131
|
-
### **2.1 `useSwapV3Routes()` - Main React Hook**
|
|
190
|
+
### **2.1 `useSwapV3Routes()` - Main Aggregation React Hook**
|
|
132
191
|
|
|
133
192
|
```tsx
|
|
134
193
|
import { useSwapV3Routes } from '@bitzy-app/bitzy-sdk';
|
|
@@ -139,6 +198,7 @@ function SwapComponent() {
|
|
|
139
198
|
const [amountIn, setAmountIn] = useState('1.0');
|
|
140
199
|
|
|
141
200
|
// Basic usage with defaults
|
|
201
|
+
// Get aggregated routes using SDK
|
|
142
202
|
const {
|
|
143
203
|
routes,
|
|
144
204
|
distributions,
|
|
@@ -154,7 +214,7 @@ function SwapComponent() {
|
|
|
154
214
|
clearError
|
|
155
215
|
} = useSwapV3Routes(srcToken, dstToken, amountIn, 3637);
|
|
156
216
|
|
|
157
|
-
// Advanced usage with custom configuration
|
|
217
|
+
// Advanced usage with custom aggregation configuration
|
|
158
218
|
const swapConfig = {
|
|
159
219
|
apiBaseUrl: 'https://api-public.bitzy.app',
|
|
160
220
|
config: {
|
|
@@ -212,11 +272,11 @@ function SwapComponent() {
|
|
|
212
272
|
|
|
213
273
|
## **3. Prepare to Swap Using Response**
|
|
214
274
|
|
|
215
|
-
Based on the main repository implementation, here's how to use the SDK response to prepare and execute swaps:
|
|
275
|
+
Based on the main repository implementation, here's how to use the aggregator SDK response to prepare and execute optimized swaps:
|
|
216
276
|
|
|
217
|
-
### **3.1 Complete Swap Implementation**
|
|
277
|
+
### **3.1 Complete Aggregated Swap Implementation**
|
|
218
278
|
|
|
219
|
-
Here are generic examples showing how to execute swaps using direct contract calls with the SDK response data:
|
|
279
|
+
Here are generic examples showing how to execute aggregated swaps using direct contract calls with the SDK response data:
|
|
220
280
|
|
|
221
281
|
#### **Example 1: Using Viem with BitzyAggregator Contract**
|
|
222
282
|
|
|
@@ -234,7 +294,7 @@ function SwapComponent() {
|
|
|
234
294
|
const { address, publicClient } = useAccount();
|
|
235
295
|
const { writeContract } = useWriteContract();
|
|
236
296
|
|
|
237
|
-
// Get
|
|
297
|
+
// Get aggregated routes using SDK
|
|
238
298
|
const {
|
|
239
299
|
routes,
|
|
240
300
|
distributions,
|
|
@@ -263,7 +323,7 @@ function SwapComponent() {
|
|
|
263
323
|
useOnlinePartCount: true,
|
|
264
324
|
});
|
|
265
325
|
|
|
266
|
-
// Execute swap using direct contract call
|
|
326
|
+
// Execute aggregated swap using direct contract call
|
|
267
327
|
const handleSwap = useCallback(async () => {
|
|
268
328
|
if (!srcToken || !dstToken || !routes.length || !address) return;
|
|
269
329
|
|
|
@@ -311,7 +371,7 @@ function SwapComponent() {
|
|
|
311
371
|
return;
|
|
312
372
|
}
|
|
313
373
|
|
|
314
|
-
// Regular swap using splitTrade
|
|
374
|
+
// Regular aggregated swap using splitTrade
|
|
315
375
|
const tradeRoutes = routes.map((route, i) => {
|
|
316
376
|
const amountInPart = amountInParts[i];
|
|
317
377
|
const amountOutMinPart = amountOutRoutes[i].times(1 - slippageBN);
|
|
@@ -408,7 +468,7 @@ function SwapWithEthers() {
|
|
|
408
468
|
const [provider, setProvider] = useState<ethers.BrowserProvider | null>(null);
|
|
409
469
|
const [signer, setSigner] = useState<ethers.JsonRpcSigner | null>(null);
|
|
410
470
|
|
|
411
|
-
// Get
|
|
471
|
+
// Get aggregated routes using SDK
|
|
412
472
|
const {
|
|
413
473
|
routes,
|
|
414
474
|
distributions,
|
|
@@ -421,7 +481,7 @@ function SwapWithEthers() {
|
|
|
421
481
|
fetchRoute
|
|
422
482
|
} = useSwapV3Routes(srcToken, dstToken, amountIn, 3637);
|
|
423
483
|
|
|
424
|
-
// Execute swap using ethers.js
|
|
484
|
+
// Execute aggregated swap using ethers.js
|
|
425
485
|
const executeSwap = async () => {
|
|
426
486
|
if (!signer || !routes.length) return;
|
|
427
487
|
|
|
@@ -491,7 +551,7 @@ function SwapWithWeb3() {
|
|
|
491
551
|
const [web3, setWeb3] = useState<Web3 | null>(null);
|
|
492
552
|
const [account, setAccount] = useState<string | null>(null);
|
|
493
553
|
|
|
494
|
-
// Get
|
|
554
|
+
// Get aggregated routes using SDK
|
|
495
555
|
const {
|
|
496
556
|
routes,
|
|
497
557
|
distributions,
|
|
@@ -503,7 +563,7 @@ function SwapWithWeb3() {
|
|
|
503
563
|
fetchRoute
|
|
504
564
|
} = useSwapV3Routes(srcToken, dstToken, amountIn, 3637);
|
|
505
565
|
|
|
506
|
-
// Execute swap using web3.js
|
|
566
|
+
// Execute aggregated swap using web3.js
|
|
507
567
|
const executeSwap = async () => {
|
|
508
568
|
if (!web3 || !account || !routes.length) return;
|
|
509
569
|
|
|
@@ -572,9 +632,9 @@ function SwapWithWeb3() {
|
|
|
572
632
|
}
|
|
573
633
|
```
|
|
574
634
|
|
|
575
|
-
### **3.2 Key Data from SDK Response**
|
|
635
|
+
### **3.2 Key Data from Aggregator SDK Response**
|
|
576
636
|
|
|
577
|
-
The SDK provides all the necessary data for swap execution:
|
|
637
|
+
The aggregator SDK provides all the necessary data for optimized swap execution:
|
|
578
638
|
|
|
579
639
|
```typescript
|
|
580
640
|
interface SwapResult {
|
|
@@ -586,16 +646,16 @@ interface SwapResult {
|
|
|
586
646
|
isWrap?: "wrap" | "unwrap"; // Wrap/unwrap indicator
|
|
587
647
|
}
|
|
588
648
|
|
|
589
|
-
// Example usage in your swap function:
|
|
649
|
+
// Example usage in your aggregated swap function:
|
|
590
650
|
swap(
|
|
591
651
|
srcToken,
|
|
592
652
|
dstToken,
|
|
593
653
|
amountIn, // User input
|
|
594
654
|
amountOut, // Calculated from amountOutBN
|
|
595
|
-
routes, // From SDK - route details
|
|
596
|
-
distributions, // From SDK - how to split liquidity
|
|
597
|
-
amountOutRoutes, // From SDK - amounts per route
|
|
598
|
-
amountInParts, // From SDK - input amounts per part
|
|
655
|
+
routes, // From aggregator SDK - optimized route details
|
|
656
|
+
distributions, // From aggregator SDK - how to split liquidity across DEXs
|
|
657
|
+
amountOutRoutes, // From aggregator SDK - amounts per route
|
|
658
|
+
amountInParts, // From aggregator SDK - input amounts per part
|
|
599
659
|
slippageNumber // User setting
|
|
600
660
|
);
|
|
601
661
|
```
|
|
@@ -609,7 +669,7 @@ NEXT_PUBLIC_BITZY_API_URL=https://api-public.bitzy.app
|
|
|
609
669
|
```
|
|
610
670
|
|
|
611
671
|
```typescript
|
|
612
|
-
// The SDK will automatically use these environment variables
|
|
672
|
+
// The aggregator SDK will automatically use these environment variables
|
|
613
673
|
const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId);
|
|
614
674
|
// Uses process.env.NEXT_PUBLIC_BITZY_API_KEY if available
|
|
615
675
|
```
|
|
@@ -620,20 +680,20 @@ const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId);
|
|
|
620
680
|
|
|
621
681
|
The `useSwapV3Routes` hook is designed for **hot reloading** and **real-time updates**:
|
|
622
682
|
|
|
623
|
-
- **Auto-updates** - Fetches fresh routes every 10 seconds
|
|
683
|
+
- **Auto-updates** - Fetches fresh aggregated routes every 10 seconds
|
|
624
684
|
- **Debounced** - Prevents excessive API calls
|
|
625
685
|
- **Error handling** - Built-in error state and recovery
|
|
626
686
|
- **Hot reload** - Automatically reinitializes when config changes
|
|
627
687
|
- **📱 React Native ready** - Works in any React environment
|
|
628
688
|
|
|
629
|
-
### **Intelligent
|
|
689
|
+
### **Intelligent Route Aggregation**
|
|
630
690
|
|
|
631
|
-
The SDK automatically optimizes swap execution based on token characteristics:
|
|
691
|
+
The aggregator SDK automatically optimizes swap execution by aggregating routes across multiple DEXs based on token characteristics:
|
|
632
692
|
|
|
633
|
-
- **High-value pairs** (BTC-USDC, ETH-USDT): Uses `partCount = 5` for optimal
|
|
634
|
-
- **Mixed pairs** (BTC-MEME, ETH-SHIB): Uses `partCount = 1` for
|
|
635
|
-
- **Low-value pairs** (MEME-SHIB): Uses `partCount = 1` for
|
|
636
|
-
- **Online mode**: Checks minimum amount thresholds from API to determine if multi-route is beneficial
|
|
693
|
+
- **High-value pairs** (BTC-USDC, ETH-USDT): Uses `partCount = 5` for optimal multi-DEX aggregation
|
|
694
|
+
- **Mixed pairs** (BTC-MEME, ETH-SHIB): Uses `partCount = 1` for simplified aggregation
|
|
695
|
+
- **Low-value pairs** (MEME-SHIB): Uses `partCount = 1` for simplified aggregation
|
|
696
|
+
- **Online mode**: Checks minimum amount thresholds from API to determine if multi-route aggregation is beneficial
|
|
637
697
|
|
|
638
698
|
### **High-Value Tokens (Network-Specific)**
|
|
639
699
|
|
|
@@ -661,7 +721,7 @@ const highValueTokens = [
|
|
|
661
721
|
### **Functions**
|
|
662
722
|
|
|
663
723
|
#### **`fetchSwapRoute(options, config?)`**
|
|
664
|
-
Main function for
|
|
724
|
+
Main function for aggregating swap routes across multiple DEXs in any environment.
|
|
665
725
|
|
|
666
726
|
**Parameters:**
|
|
667
727
|
- `options: SwapOptions` - Swap parameters
|
|
@@ -669,8 +729,10 @@ Main function for fetching swap routes in any environment.
|
|
|
669
729
|
|
|
670
730
|
**Returns:** `Promise<SwapResult>`
|
|
671
731
|
|
|
732
|
+
**Note:** The `publicClient` is automatically created using default RPC endpoints if not provided. You can optionally inject your own `PublicClient` instance (e.g., from wagmi) for better performance and connection reuse.
|
|
733
|
+
|
|
672
734
|
#### **`fetchBatchSwapRoutes(requests)`**
|
|
673
|
-
|
|
735
|
+
Aggregate multiple routes simultaneously across different token pairs.
|
|
674
736
|
|
|
675
737
|
**Parameters:**
|
|
676
738
|
- `requests: Array<{options: SwapOptions, config?: FetchSwapRouteConfig}>`
|
|
@@ -678,18 +740,19 @@ Fetch multiple routes simultaneously.
|
|
|
678
740
|
**Returns:** `Promise<Array<{success: boolean, data?: SwapResult, error?: string}>>`
|
|
679
741
|
|
|
680
742
|
#### **`getSwapQuote(srcToken, dstToken, amountIn, chainId, config?)`**
|
|
681
|
-
Get
|
|
743
|
+
Get an aggregated price quote without full routing details.
|
|
682
744
|
|
|
683
745
|
**Returns:** `Promise<{amountOut: string, routes: number}>`
|
|
684
746
|
|
|
685
747
|
#### **`fetchSwapRouteSimple(srcToken, dstToken, amountIn, chainId)`**
|
|
686
|
-
Simplified function with minimal parameters.
|
|
748
|
+
Simplified aggregation function with minimal parameters.
|
|
687
749
|
|
|
688
750
|
**Returns:** `Promise<SwapResult>`
|
|
689
751
|
|
|
690
752
|
### **React Hooks**
|
|
691
753
|
|
|
692
754
|
#### **`useSwapV3Routes(srcToken, dstToken, amountIn, chainId, config?)`**
|
|
755
|
+
Aggregation React hook for real-time route optimization.
|
|
693
756
|
|
|
694
757
|
**Parameters:**
|
|
695
758
|
- `srcToken: Token | null` - Source token
|
|
@@ -725,7 +788,7 @@ interface SwapOptions {
|
|
|
725
788
|
srcToken: Token; // Source token
|
|
726
789
|
dstToken: Token; // Destination token
|
|
727
790
|
chainId: number; // Network chain ID
|
|
728
|
-
partCount?: number; // Optional:
|
|
791
|
+
partCount?: number; // Optional: Aggregation parts
|
|
729
792
|
}
|
|
730
793
|
```
|
|
731
794
|
|
|
@@ -734,10 +797,11 @@ interface SwapOptions {
|
|
|
734
797
|
interface FetchSwapRouteConfig {
|
|
735
798
|
apiBaseUrl?: string; // Optional: API base URL (defaults to https://api-public.bitzy.app)
|
|
736
799
|
networks?: Record<number, any>; // Optional: Custom network configs
|
|
737
|
-
defaultPartCount?: number; // Optional: Default parts (defaults to 5)
|
|
800
|
+
defaultPartCount?: number; // Optional: Default aggregation parts (defaults to 5)
|
|
738
801
|
timeout?: number; // Optional: Request timeout (defaults to 30000)
|
|
739
802
|
headers?: Record<string, string>; // Optional: Custom HTTP headers (defaults to {})
|
|
740
803
|
forcePartCount?: number; // Optional: Force specific partCount, overriding intelligent calculation
|
|
804
|
+
publicClient?: PublicClient; // Optional: Viem PublicClient instance (auto-created if not provided)
|
|
741
805
|
}
|
|
742
806
|
```
|
|
743
807
|
|
|
@@ -797,7 +861,7 @@ app.post('/api/swap/routes', async (req, res) => {
|
|
|
797
861
|
}
|
|
798
862
|
});
|
|
799
863
|
|
|
800
|
-
// Batch processing
|
|
864
|
+
// Batch aggregation processing
|
|
801
865
|
app.post('/api/swap/batch', async (req, res) => {
|
|
802
866
|
const { swaps } = req.body;
|
|
803
867
|
|
|
@@ -866,11 +930,14 @@ The package includes default configurations for:
|
|
|
866
930
|
|
|
867
931
|
### **Default Values**
|
|
868
932
|
|
|
869
|
-
When no config is provided, the SDK uses these sensible defaults:
|
|
933
|
+
When no config is provided, the aggregator SDK uses these sensible defaults:
|
|
870
934
|
|
|
871
935
|
- **API URL**: `https://api-public.bitzy.app` (from `DEFAULT_API_BASE_URL`)
|
|
872
936
|
- **API Key**: From `NEXT_PUBLIC_BITZY_API_KEY` environment variable or fallback
|
|
873
937
|
- **Addresses**: Network-specific defaults from `CONTRACT_ADDRESSES`
|
|
938
|
+
- **RPC Endpoints**:
|
|
939
|
+
- Botanix Mainnet (3637): `https://rpc.botanixlabs.com`
|
|
940
|
+
- Botanix Testnet (3636): `https://node.botanixlabs.dev`
|
|
874
941
|
- **PartCount**: `5` for high-value pairs, `1` for others
|
|
875
942
|
- **Timeout**: `30` seconds
|
|
876
943
|
- **Refresh**: `10` seconds
|
|
@@ -914,11 +981,11 @@ src/
|
|
|
914
981
|
|
|
915
982
|
## **Why This Design?**
|
|
916
983
|
|
|
917
|
-
- **Focused** - Just the essential
|
|
918
|
-
- **Hot Reload** - Perfect for React development
|
|
919
|
-
- **Universal** - Common functions work everywhere
|
|
920
|
-
- **Lightweight** - Minimal dependencies
|
|
921
|
-
- **Type Safe** - Full TypeScript support
|
|
984
|
+
- **Focused** - Just the essential aggregation functionality
|
|
985
|
+
- **Hot Reload** - Perfect for React development with real-time aggregation
|
|
986
|
+
- **Universal** - Common functions work everywhere for multi-DEX aggregation
|
|
987
|
+
- **Lightweight** - Minimal dependencies for efficient aggregation
|
|
988
|
+
- **Type Safe** - Full TypeScript support for aggregation operations
|
|
922
989
|
|
|
923
990
|
## 📄 **License**
|
|
924
991
|
|
package/dist/api/Client.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export declare class APIClient {
|
|
|
37
37
|
getAssetMinimum(): Promise<any>;
|
|
38
38
|
/**
|
|
39
39
|
* Build query string from parameters
|
|
40
|
+
* Arrays are formatted as JSON strings with quotes encoded as %22, brackets not encoded
|
|
41
|
+
* Example: typeId=["1","2"] becomes typeId=[%221%22,%222%22]
|
|
40
42
|
*/
|
|
41
43
|
private buildQueryString;
|
|
42
44
|
}
|
package/dist/api/Client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAmB,cAAc,EAAE,MAAM,UAAU,CAAC;AAIlE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA0B;IACjD,OAAO,CAAC,MAAM,CAAkB;IAEhC,OAAO;IAIP;;;;;;;;OAQG;IACH,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS;
|
|
1
|
+
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAmB,cAAc,EAAE,MAAM,UAAU,CAAC;AAIlE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA0B;IACjD,OAAO,CAAC,MAAM,CAAkB;IAEhC,OAAO;IAIP;;;;;;;;OAQG;IACH,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS;IAoBtD;;OAEG;IACH,MAAM,CAAC,aAAa,IAAI,IAAI;IAI5B;;OAEG;YACW,OAAO;IAoDrB;;OAEG;IACG,SAAS,CACb,QAAQ,EAAE,KAAK,EACf,QAAQ,EAAE,KAAK,EACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EAAE,EACf,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,cAAc,CAAC;IAgB1B;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC;IAMrC;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;CAgBzB"}
|
|
@@ -14,6 +14,13 @@ export interface FetchSwapRouteConfig {
|
|
|
14
14
|
* - Low-value tokens (meme tokens, small caps): partCount = 1 (simpler routing)
|
|
15
15
|
*/
|
|
16
16
|
forcePartCount?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Optional PublicClient from viem
|
|
19
|
+
* - If provided, will be used for contract calls
|
|
20
|
+
* - If not provided, SDK will automatically create one using RPC_CONFIG
|
|
21
|
+
* - Useful when you already have a PublicClient instance (e.g., from wagmi)
|
|
22
|
+
*/
|
|
23
|
+
publicClient?: PublicClient;
|
|
17
24
|
}
|
|
18
25
|
/**
|
|
19
26
|
* Common function to fetch swap routes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FetchSwapRoute.d.ts","sourceRoot":"","sources":["../../src/common/FetchSwapRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAuB,MAAM,UAAU,CAAC;AAS/E,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEpC,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"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A;CAAE,CAAC,CAehD;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,KAAK,CAAC;IAChB,QAAQ,EAAE,KAAK,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,qBAAqB,EAC9B,MAAM,GAAE,oBAAyB,GAChC,OAAO,CAAC,UAAU,CAAC,CAcrB;AAGD,eAAe,cAAc,CAAC"}
|
|
@@ -24,6 +24,15 @@ export declare const CONTRACT_ADDRESSES: ChainWrap<{
|
|
|
24
24
|
nativeAddress: Address;
|
|
25
25
|
gasLimit: bigint;
|
|
26
26
|
}>;
|
|
27
|
+
export declare const RPC_CONFIG: ChainWrap<{
|
|
28
|
+
rpcUrls: string[];
|
|
29
|
+
name: string;
|
|
30
|
+
nativeCurrency: {
|
|
31
|
+
name: string;
|
|
32
|
+
symbol: string;
|
|
33
|
+
decimals: number;
|
|
34
|
+
};
|
|
35
|
+
}>;
|
|
27
36
|
export declare const LIQUIDITY_SOURCES: ChainWrap<LiquiditySourcesConfig>;
|
|
28
37
|
export declare const getLiquiditySources: (chainId: number) => LiquiditySourcesConfig;
|
|
29
38
|
export declare const getContractAddresses: (chainId: number) => {
|
|
@@ -41,6 +50,15 @@ export declare const getContractAddresses: (chainId: number) => {
|
|
|
41
50
|
gasLimit: bigint;
|
|
42
51
|
};
|
|
43
52
|
export declare const getDexRouters: (chainId: number) => Record<string, `0x${string}`>;
|
|
53
|
+
export declare const getRpcConfig: (chainId: number) => {
|
|
54
|
+
rpcUrls: string[];
|
|
55
|
+
name: string;
|
|
56
|
+
nativeCurrency: {
|
|
57
|
+
name: string;
|
|
58
|
+
symbol: string;
|
|
59
|
+
decimals: number;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
44
62
|
export declare const DEFAULT_NETWORKS: ChainWrap<{
|
|
45
63
|
factoryAddress: Address;
|
|
46
64
|
v3FactoryAddress: Address;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAG7D,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AAGX,eAAO,MAAM,WAAW,EAAE,OACoB,CAAC;AAC/C,eAAO,MAAM,aAAa,EAAE,OACkB,CAAC;AAG/C,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,eAAe,QAAQ,CAAC;AAGrC,eAAO,MAAM,oBAAoB,iCAAiC,CAAC;AAGnE,eAAO,MAAM,WAAW,EAAE,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAa1D,CAAC;AAGF,eAAO,MAAM,kBAAkB,EAAE,SAAS,CAAC;IACzC,cAAc,EAAE,OAAO,CAAC;IACxB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,wBAAwB,EAAE,OAAO,CAAC;IAClC,qBAAqB,EAAE,OAAO,CAAC;IAC/B,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB,CA+BA,CAAC;AAGF,eAAO,MAAM,iBAAiB,EAAE,SAAS,CAAC,sBAAsB,CAW/D,CAAC;AAGF,eAAO,MAAM,mBAAmB,GAC9B,SAAS,MAAM,KACd,sBAEF,CAAC;AAEF,eAAO,MAAM,oB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BA,CAAC;AAGF,eAAO,MAAM,iBAAiB,EAAE,SAAS,CAAC,sBAAsB,CAW/D,CAAC;AAGF,eAAO,MAAM,mBAAmB,GAC9B,SAAS,MAAM,KACd,sBAEF,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM;oBAlGlC,OAAO;sBACL,OAAO;8BACC,OAAO;2BACV,OAAO;mBACf,OAAO;uBACH,OAAO;gBACd,OAAO;wBACC,OAAO;uBACR,OAAO;oBACV,OAAO;mBACR,OAAO;cACZ,MAAM;CAyFjB,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,kCAE5C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM;aA3DjC,MAAM,EAAE;UACX,MAAM;oBACI;QACd,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB;CAuDF,CAAC;AAGF,eAAO,MAAM,gBAAgB;oBA/GX,OAAO;sBACL,OAAO;8BACC,OAAO;2BACV,OAAO;mBACf,OAAO;uBACH,OAAO;gBACd,OAAO;wBACC,OAAO;uBACR,OAAO;oBACV,OAAO;mBACR,OAAO;cACZ,MAAM;EAoGgC,CAAC;AACnD,eAAO,MAAM,UAAU,+BAA0B,CAAC;AAGlD,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AAGX,eAAO,MAAM,WAAW;;;;;;;CAOd,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -274,6 +274,13 @@ interface FetchSwapRouteConfig {
|
|
|
274
274
|
* - Low-value tokens (meme tokens, small caps): partCount = 1 (simpler routing)
|
|
275
275
|
*/
|
|
276
276
|
forcePartCount?: number;
|
|
277
|
+
/**
|
|
278
|
+
* Optional PublicClient from viem
|
|
279
|
+
* - If provided, will be used for contract calls
|
|
280
|
+
* - If not provided, SDK will automatically create one using RPC_CONFIG
|
|
281
|
+
* - Useful when you already have a PublicClient instance (e.g., from wagmi)
|
|
282
|
+
*/
|
|
283
|
+
publicClient?: PublicClient;
|
|
277
284
|
}
|
|
278
285
|
/**
|
|
279
286
|
* Common function to fetch swap routes
|
|
@@ -454,6 +461,8 @@ declare class APIClient {
|
|
|
454
461
|
getAssetMinimum(): Promise<any>;
|
|
455
462
|
/**
|
|
456
463
|
* Build query string from parameters
|
|
464
|
+
* Arrays are formatted as JSON strings with quotes encoded as %22, brackets not encoded
|
|
465
|
+
* Example: typeId=["1","2"] becomes typeId=[%221%22,%222%22]
|
|
457
466
|
*/
|
|
458
467
|
private buildQueryString;
|
|
459
468
|
}
|
|
@@ -467,6 +476,11 @@ interface SwapV3ServiceConfig {
|
|
|
467
476
|
declare class SwapV3Service {
|
|
468
477
|
private config;
|
|
469
478
|
constructor(config: SwapV3ServiceConfig);
|
|
479
|
+
/**
|
|
480
|
+
* Get or create publicClient for the given chainId
|
|
481
|
+
* Returns existing publicClient if provided, otherwise creates a default one
|
|
482
|
+
*/
|
|
483
|
+
private getPublicClient;
|
|
470
484
|
/**
|
|
471
485
|
* Fetch swap routes for V3 swaps
|
|
472
486
|
* This is the core function extracted from the React hook
|