@bitzy-app/bitzy-sdk 0.0.6 → 0.0.7

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 (3) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +58 -47
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.7](https://github.com/bitzy-app/bitzy-sdk/compare/v0.0.6...v0.0.7) (2025-09-17)
2
+
3
+
4
+
1
5
  ## [0.0.6](https://github.com/bitzy-app/bitzy-sdk/compare/v0.0.5...v0.0.6) (2025-09-08)
2
6
 
3
7
 
package/README.md CHANGED
@@ -1,14 +1,23 @@
1
- # Bitzy Swap V3 - Common Function & Hot Hook
1
+ # Bitzy Aggregator SDK - Multi-DEX Route Aggregation
2
2
 
3
- A comprehensive SDK for fetching swap routes and executing swaps on Bitzy's decentralized exchange. Provides both **common functions** for any environment and **React hooks** for frontend applications.
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 Routing** - Automatic optimization based on token characteristics
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 Finding Function**
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,7 @@ console.log('Amount out:', result.amountOutBN.toFixed());
54
63
  console.log('Distributions:', result.distributions);
55
64
  ```
56
65
 
57
- ### **1.2 `fetchBatchSwapRoutes()` - Multiple Routes at Once**
66
+ ### **1.2 `fetchBatchSwapRoutes()` - Batch Route Aggregation**
58
67
 
59
68
  ```typescript
60
69
  import { fetchBatchSwapRoutes } from '@bitzy-app/bitzy-sdk';
@@ -91,7 +100,7 @@ results.forEach((result, index) => {
91
100
  });
92
101
  ```
93
102
 
94
- ### **1.3 `getSwapQuote()` - Simple Price Quote**
103
+ ### **1.3 `getSwapQuote()` - Aggregated Price Quote**
95
104
 
96
105
  ```typescript
97
106
  import { getSwapQuote } from '@bitzy-app/bitzy-sdk';
@@ -109,7 +118,7 @@ console.log('Amount out:', quote.amountOut);
109
118
  console.log('Route count:', quote.routes);
110
119
  ```
111
120
 
112
- ### **1.4 `fetchSwapRouteSimple()` - Minimal Configuration**
121
+ ### **1.4 `fetchSwapRouteSimple()` - Simple Aggregation**
113
122
 
114
123
  ```typescript
115
124
  import { fetchSwapRouteSimple } from '@bitzy-app/bitzy-sdk';
@@ -128,7 +137,7 @@ console.log('Best route:', result.routes[0]);
128
137
 
129
138
  ## **2. Using React Hooks**
130
139
 
131
- ### **2.1 `useSwapV3Routes()` - Main React Hook**
140
+ ### **2.1 `useSwapV3Routes()` - Main Aggregation React Hook**
132
141
 
133
142
  ```tsx
134
143
  import { useSwapV3Routes } from '@bitzy-app/bitzy-sdk';
@@ -139,6 +148,7 @@ function SwapComponent() {
139
148
  const [amountIn, setAmountIn] = useState('1.0');
140
149
 
141
150
  // Basic usage with defaults
151
+ // Get aggregated routes using SDK
142
152
  const {
143
153
  routes,
144
154
  distributions,
@@ -154,7 +164,7 @@ function SwapComponent() {
154
164
  clearError
155
165
  } = useSwapV3Routes(srcToken, dstToken, amountIn, 3637);
156
166
 
157
- // Advanced usage with custom configuration
167
+ // Advanced usage with custom aggregation configuration
158
168
  const swapConfig = {
159
169
  apiBaseUrl: 'https://api-public.bitzy.app',
160
170
  config: {
@@ -212,11 +222,11 @@ function SwapComponent() {
212
222
 
213
223
  ## **3. Prepare to Swap Using Response**
214
224
 
215
- Based on the main repository implementation, here's how to use the SDK response to prepare and execute swaps:
225
+ Based on the main repository implementation, here's how to use the aggregator SDK response to prepare and execute optimized swaps:
216
226
 
217
- ### **3.1 Complete Swap Implementation**
227
+ ### **3.1 Complete Aggregated Swap Implementation**
218
228
 
219
- Here are generic examples showing how to execute swaps using direct contract calls with the SDK response data:
229
+ Here are generic examples showing how to execute aggregated swaps using direct contract calls with the SDK response data:
220
230
 
221
231
  #### **Example 1: Using Viem with BitzyAggregator Contract**
222
232
 
@@ -234,7 +244,7 @@ function SwapComponent() {
234
244
  const { address, publicClient } = useAccount();
235
245
  const { writeContract } = useWriteContract();
236
246
 
237
- // Get swap routes using SDK
247
+ // Get aggregated routes using SDK
238
248
  const {
239
249
  routes,
240
250
  distributions,
@@ -263,7 +273,7 @@ function SwapComponent() {
263
273
  useOnlinePartCount: true,
264
274
  });
265
275
 
266
- // Execute swap using direct contract call
276
+ // Execute aggregated swap using direct contract call
267
277
  const handleSwap = useCallback(async () => {
268
278
  if (!srcToken || !dstToken || !routes.length || !address) return;
269
279
 
@@ -311,7 +321,7 @@ function SwapComponent() {
311
321
  return;
312
322
  }
313
323
 
314
- // Regular swap using splitTrade
324
+ // Regular aggregated swap using splitTrade
315
325
  const tradeRoutes = routes.map((route, i) => {
316
326
  const amountInPart = amountInParts[i];
317
327
  const amountOutMinPart = amountOutRoutes[i].times(1 - slippageBN);
@@ -408,7 +418,7 @@ function SwapWithEthers() {
408
418
  const [provider, setProvider] = useState<ethers.BrowserProvider | null>(null);
409
419
  const [signer, setSigner] = useState<ethers.JsonRpcSigner | null>(null);
410
420
 
411
- // Get swap routes using SDK
421
+ // Get aggregated routes using SDK
412
422
  const {
413
423
  routes,
414
424
  distributions,
@@ -421,7 +431,7 @@ function SwapWithEthers() {
421
431
  fetchRoute
422
432
  } = useSwapV3Routes(srcToken, dstToken, amountIn, 3637);
423
433
 
424
- // Execute swap using ethers.js
434
+ // Execute aggregated swap using ethers.js
425
435
  const executeSwap = async () => {
426
436
  if (!signer || !routes.length) return;
427
437
 
@@ -491,7 +501,7 @@ function SwapWithWeb3() {
491
501
  const [web3, setWeb3] = useState<Web3 | null>(null);
492
502
  const [account, setAccount] = useState<string | null>(null);
493
503
 
494
- // Get swap routes using SDK
504
+ // Get aggregated routes using SDK
495
505
  const {
496
506
  routes,
497
507
  distributions,
@@ -503,7 +513,7 @@ function SwapWithWeb3() {
503
513
  fetchRoute
504
514
  } = useSwapV3Routes(srcToken, dstToken, amountIn, 3637);
505
515
 
506
- // Execute swap using web3.js
516
+ // Execute aggregated swap using web3.js
507
517
  const executeSwap = async () => {
508
518
  if (!web3 || !account || !routes.length) return;
509
519
 
@@ -572,9 +582,9 @@ function SwapWithWeb3() {
572
582
  }
573
583
  ```
574
584
 
575
- ### **3.2 Key Data from SDK Response**
585
+ ### **3.2 Key Data from Aggregator SDK Response**
576
586
 
577
- The SDK provides all the necessary data for swap execution:
587
+ The aggregator SDK provides all the necessary data for optimized swap execution:
578
588
 
579
589
  ```typescript
580
590
  interface SwapResult {
@@ -586,16 +596,16 @@ interface SwapResult {
586
596
  isWrap?: "wrap" | "unwrap"; // Wrap/unwrap indicator
587
597
  }
588
598
 
589
- // Example usage in your swap function:
599
+ // Example usage in your aggregated swap function:
590
600
  swap(
591
601
  srcToken,
592
602
  dstToken,
593
603
  amountIn, // User input
594
604
  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
605
+ routes, // From aggregator SDK - optimized route details
606
+ distributions, // From aggregator SDK - how to split liquidity across DEXs
607
+ amountOutRoutes, // From aggregator SDK - amounts per route
608
+ amountInParts, // From aggregator SDK - input amounts per part
599
609
  slippageNumber // User setting
600
610
  );
601
611
  ```
@@ -609,7 +619,7 @@ NEXT_PUBLIC_BITZY_API_URL=https://api-public.bitzy.app
609
619
  ```
610
620
 
611
621
  ```typescript
612
- // The SDK will automatically use these environment variables
622
+ // The aggregator SDK will automatically use these environment variables
613
623
  const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId);
614
624
  // Uses process.env.NEXT_PUBLIC_BITZY_API_KEY if available
615
625
  ```
@@ -620,20 +630,20 @@ const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId);
620
630
 
621
631
  The `useSwapV3Routes` hook is designed for **hot reloading** and **real-time updates**:
622
632
 
623
- - **Auto-updates** - Fetches fresh routes every 10 seconds
633
+ - **Auto-updates** - Fetches fresh aggregated routes every 10 seconds
624
634
  - **Debounced** - Prevents excessive API calls
625
635
  - **Error handling** - Built-in error state and recovery
626
636
  - **Hot reload** - Automatically reinitializes when config changes
627
637
  - **📱 React Native ready** - Works in any React environment
628
638
 
629
- ### **Intelligent Routing**
639
+ ### **Intelligent Route Aggregation**
630
640
 
631
- The SDK automatically optimizes swap execution based on token characteristics:
641
+ The aggregator SDK automatically optimizes swap execution by aggregating routes across multiple DEXs based on token characteristics:
632
642
 
633
- - **High-value pairs** (BTC-USDC, ETH-USDT): Uses `partCount = 5` for optimal execution
634
- - **Mixed pairs** (BTC-MEME, ETH-SHIB): Uses `partCount = 1` for simplicity
635
- - **Low-value pairs** (MEME-SHIB): Uses `partCount = 1` for simplicity
636
- - **Online mode**: Checks minimum amount thresholds from API to determine if multi-route is beneficial
643
+ - **High-value pairs** (BTC-USDC, ETH-USDT): Uses `partCount = 5` for optimal multi-DEX aggregation
644
+ - **Mixed pairs** (BTC-MEME, ETH-SHIB): Uses `partCount = 1` for simplified aggregation
645
+ - **Low-value pairs** (MEME-SHIB): Uses `partCount = 1` for simplified aggregation
646
+ - **Online mode**: Checks minimum amount thresholds from API to determine if multi-route aggregation is beneficial
637
647
 
638
648
  ### **High-Value Tokens (Network-Specific)**
639
649
 
@@ -661,7 +671,7 @@ const highValueTokens = [
661
671
  ### **Functions**
662
672
 
663
673
  #### **`fetchSwapRoute(options, config?)`**
664
- Main function for fetching swap routes in any environment.
674
+ Main function for aggregating swap routes across multiple DEXs in any environment.
665
675
 
666
676
  **Parameters:**
667
677
  - `options: SwapOptions` - Swap parameters
@@ -670,7 +680,7 @@ Main function for fetching swap routes in any environment.
670
680
  **Returns:** `Promise<SwapResult>`
671
681
 
672
682
  #### **`fetchBatchSwapRoutes(requests)`**
673
- Fetch multiple routes simultaneously.
683
+ Aggregate multiple routes simultaneously across different token pairs.
674
684
 
675
685
  **Parameters:**
676
686
  - `requests: Array<{options: SwapOptions, config?: FetchSwapRouteConfig}>`
@@ -678,18 +688,19 @@ Fetch multiple routes simultaneously.
678
688
  **Returns:** `Promise<Array<{success: boolean, data?: SwapResult, error?: string}>>`
679
689
 
680
690
  #### **`getSwapQuote(srcToken, dstToken, amountIn, chainId, config?)`**
681
- Get a simple price quote without full routing details.
691
+ Get an aggregated price quote without full routing details.
682
692
 
683
693
  **Returns:** `Promise<{amountOut: string, routes: number}>`
684
694
 
685
695
  #### **`fetchSwapRouteSimple(srcToken, dstToken, amountIn, chainId)`**
686
- Simplified function with minimal parameters.
696
+ Simplified aggregation function with minimal parameters.
687
697
 
688
698
  **Returns:** `Promise<SwapResult>`
689
699
 
690
700
  ### **React Hooks**
691
701
 
692
702
  #### **`useSwapV3Routes(srcToken, dstToken, amountIn, chainId, config?)`**
703
+ Aggregation React hook for real-time route optimization.
693
704
 
694
705
  **Parameters:**
695
706
  - `srcToken: Token | null` - Source token
@@ -725,7 +736,7 @@ interface SwapOptions {
725
736
  srcToken: Token; // Source token
726
737
  dstToken: Token; // Destination token
727
738
  chainId: number; // Network chain ID
728
- partCount?: number; // Optional: Liquidity parts
739
+ partCount?: number; // Optional: Aggregation parts
729
740
  }
730
741
  ```
731
742
 
@@ -734,7 +745,7 @@ interface SwapOptions {
734
745
  interface FetchSwapRouteConfig {
735
746
  apiBaseUrl?: string; // Optional: API base URL (defaults to https://api-public.bitzy.app)
736
747
  networks?: Record<number, any>; // Optional: Custom network configs
737
- defaultPartCount?: number; // Optional: Default parts (defaults to 5)
748
+ defaultPartCount?: number; // Optional: Default aggregation parts (defaults to 5)
738
749
  timeout?: number; // Optional: Request timeout (defaults to 30000)
739
750
  headers?: Record<string, string>; // Optional: Custom HTTP headers (defaults to {})
740
751
  forcePartCount?: number; // Optional: Force specific partCount, overriding intelligent calculation
@@ -797,7 +808,7 @@ app.post('/api/swap/routes', async (req, res) => {
797
808
  }
798
809
  });
799
810
 
800
- // Batch processing
811
+ // Batch aggregation processing
801
812
  app.post('/api/swap/batch', async (req, res) => {
802
813
  const { swaps } = req.body;
803
814
 
@@ -866,7 +877,7 @@ The package includes default configurations for:
866
877
 
867
878
  ### **Default Values**
868
879
 
869
- When no config is provided, the SDK uses these sensible defaults:
880
+ When no config is provided, the aggregator SDK uses these sensible defaults:
870
881
 
871
882
  - **API URL**: `https://api-public.bitzy.app` (from `DEFAULT_API_BASE_URL`)
872
883
  - **API Key**: From `NEXT_PUBLIC_BITZY_API_KEY` environment variable or fallback
@@ -914,11 +925,11 @@ src/
914
925
 
915
926
  ## **Why This Design?**
916
927
 
917
- - **Focused** - Just the essential swap functionality
918
- - **Hot Reload** - Perfect for React development
919
- - **Universal** - Common functions work everywhere
920
- - **Lightweight** - Minimal dependencies
921
- - **Type Safe** - Full TypeScript support
928
+ - **Focused** - Just the essential aggregation functionality
929
+ - **Hot Reload** - Perfect for React development with real-time aggregation
930
+ - **Universal** - Common functions work everywhere for multi-DEX aggregation
931
+ - **Lightweight** - Minimal dependencies for efficient aggregation
932
+ - **Type Safe** - Full TypeScript support for aggregation operations
922
933
 
923
934
  ## 📄 **License**
924
935
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitzy-app/bitzy-sdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Bitzy Swap V3 Routes SDK for frontend and backend applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",