@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.
- package/LICENSE +21 -0
- package/README.md +932 -0
- package/dist/BitzySwapSDK.d.ts +32 -0
- package/dist/BitzySwapSDK.d.ts.map +1 -0
- package/dist/__tests__/setup.d.ts +9 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/api/Client.d.ts +43 -0
- package/dist/api/Client.d.ts.map +1 -0
- package/dist/common/FetchSwapRoute.d.ts +55 -0
- package/dist/common/FetchSwapRoute.d.ts.map +1 -0
- package/dist/constants/Abis.d.ts +46 -0
- package/dist/constants/Abis.d.ts.map +1 -0
- package/dist/constants/index.d.ts +71 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/hooks/useSwapV3Routes.d.ts +107 -0
- package/dist/hooks/useSwapV3Routes.d.ts.map +1 -0
- package/dist/index.d.ts +800 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/services/SwapV3Service.d.ts +64 -0
- package/dist/services/SwapV3Service.d.ts.map +1 -0
- package/dist/types/index.d.ts +259 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/PartCount.d.ts +101 -0
- package/dist/utils/PartCount.d.ts.map +1 -0
- package/dist/utils/index.d.ts +68 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SwapOptions, SwapResult, SwapV3AddressConfig } from "./types";
|
|
2
|
+
export interface BitzySwapSDKConfig {
|
|
3
|
+
apiBaseUrl: string;
|
|
4
|
+
networks?: Record<number, any>;
|
|
5
|
+
defaultPartCount?: number;
|
|
6
|
+
timeout?: number;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export declare class BitzySwapSDK {
|
|
10
|
+
private swapService;
|
|
11
|
+
private apiClient;
|
|
12
|
+
constructor(config: BitzySwapSDKConfig);
|
|
13
|
+
/**
|
|
14
|
+
* Fetch swap routes for V3 swaps
|
|
15
|
+
* This is the main function that other applications will use
|
|
16
|
+
*/
|
|
17
|
+
fetchRoute(options: SwapOptions): Promise<SwapResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Get supported networks
|
|
20
|
+
*/
|
|
21
|
+
getSupportedNetworks(): number[];
|
|
22
|
+
/**
|
|
23
|
+
* Get network configuration
|
|
24
|
+
*/
|
|
25
|
+
getNetworkConfig(chainId: number): SwapV3AddressConfig | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Create a new instance with custom configuration
|
|
28
|
+
*/
|
|
29
|
+
static create(config: BitzySwapSDKConfig): BitzySwapSDK;
|
|
30
|
+
}
|
|
31
|
+
export default BitzySwapSDK;
|
|
32
|
+
//# sourceMappingURL=BitzySwapSDK.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitzySwapSDK.d.ts","sourceRoot":"","sources":["../src/BitzySwapSDK.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,WAAW,EACX,UAAU,EAGV,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,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;CAClC;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAAgB;IACnC,OAAO,CAAC,SAAS,CAAY;gBAEjB,MAAM,EAAE,kBAAkB;IAkCtC;;;OAGG;IACG,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAI3D;;OAEG;IACH,oBAAoB,IAAI,MAAM,EAAE;IAIhC;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM;IAIhC;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY;CAGxD;AAGD,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const originalConsoleError: {
|
|
2
|
+
(...data: any[]): void;
|
|
3
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
4
|
+
};
|
|
5
|
+
declare const originalConsoleWarn: {
|
|
6
|
+
(...data: any[]): void;
|
|
7
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/__tests__/setup.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,oBAAoB;;;CAAgB,CAAC;AAC3C,QAAA,MAAM,mBAAmB;;;CAAe,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Token, PathV3Response } from "../types";
|
|
2
|
+
export interface APIClientConfig {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
timeout: number;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export declare class APIClient {
|
|
8
|
+
private static instance;
|
|
9
|
+
private config;
|
|
10
|
+
private constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Get singleton instance of APIClient
|
|
13
|
+
* Initializes once with API key and reuses for all requests
|
|
14
|
+
*
|
|
15
|
+
* API Key Priority:
|
|
16
|
+
* 1. Custom headers (if "authen-key" provided in config.headers)
|
|
17
|
+
* 2. NEXT_PUBLIC_BITZY_API_KEY environment variable
|
|
18
|
+
* 3. No authentication (if neither provided)
|
|
19
|
+
*/
|
|
20
|
+
static getInstance(config: APIClientConfig): APIClient;
|
|
21
|
+
/**
|
|
22
|
+
* Reset singleton instance (useful for testing or API key changes)
|
|
23
|
+
*/
|
|
24
|
+
static resetInstance(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Make HTTP request with timeout and error handling
|
|
27
|
+
*/
|
|
28
|
+
private request;
|
|
29
|
+
/**
|
|
30
|
+
* Get V3 path for swap routing
|
|
31
|
+
*/
|
|
32
|
+
getPathV3(srcToken: Token, dstToken: Token, amountIn: string, types: number[], enabledSources: number[]): Promise<PathV3Response>;
|
|
33
|
+
/**
|
|
34
|
+
* Get asset minimum partCount from SDK API
|
|
35
|
+
* Returns minimum amounts for tokens to use multiple routes
|
|
36
|
+
*/
|
|
37
|
+
getAssetMinimum(): Promise<any>;
|
|
38
|
+
/**
|
|
39
|
+
* Build query string from parameters
|
|
40
|
+
*/
|
|
41
|
+
private buildQueryString;
|
|
42
|
+
}
|
|
43
|
+
//# 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,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;IAqBtD;;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;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAczB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Token, SwapResult, SwapOptions } from "../types";
|
|
2
|
+
import { PublicClient } from "viem";
|
|
3
|
+
export interface FetchSwapRouteConfig {
|
|
4
|
+
apiBaseUrl?: string;
|
|
5
|
+
networks?: Record<number, any>;
|
|
6
|
+
defaultPartCount?: number;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Force a specific partCount, overriding intelligent calculation
|
|
11
|
+
* - If provided, this value will be used instead of automatic calculation
|
|
12
|
+
* - If not provided, uses intelligent address-based logic:
|
|
13
|
+
* - High-value tokens (BTC, ETH, USDC, USDT): partCount = 5 (better routing)
|
|
14
|
+
* - Low-value tokens (meme tokens, small caps): partCount = 1 (simpler routing)
|
|
15
|
+
*/
|
|
16
|
+
forcePartCount?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Common function to fetch swap routes
|
|
20
|
+
* Can be used in any JavaScript/TypeScript environment
|
|
21
|
+
*/
|
|
22
|
+
export declare function fetchSwapRoute(options: SwapOptions, config?: FetchSwapRouteConfig): Promise<SwapResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Batch fetch multiple swap routes
|
|
25
|
+
*/
|
|
26
|
+
export declare function fetchBatchSwapRoutes(swaps: Array<{
|
|
27
|
+
options: SwapOptions;
|
|
28
|
+
config: FetchSwapRouteConfig;
|
|
29
|
+
}>): Promise<Array<{
|
|
30
|
+
success: boolean;
|
|
31
|
+
data?: SwapResult;
|
|
32
|
+
error?: string;
|
|
33
|
+
}>>;
|
|
34
|
+
/**
|
|
35
|
+
* Simple quote function
|
|
36
|
+
*/
|
|
37
|
+
export declare function getSwapQuote(srcToken: Token, dstToken: Token, amountIn: string, chainId: number, config?: FetchSwapRouteConfig): Promise<{
|
|
38
|
+
amountOut: string;
|
|
39
|
+
routes: number;
|
|
40
|
+
}>;
|
|
41
|
+
export interface SimplifiedSwapOptions {
|
|
42
|
+
amountIn: string;
|
|
43
|
+
srcToken: Token;
|
|
44
|
+
dstToken: Token;
|
|
45
|
+
chainId: number;
|
|
46
|
+
partCount?: number;
|
|
47
|
+
publicClient?: PublicClient;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Simplified swap route fetching for 3rd party users
|
|
51
|
+
* Automatically uses network-specific liquidity sources
|
|
52
|
+
*/
|
|
53
|
+
export declare function fetchSwapRouteSimple(options: SimplifiedSwapOptions, config?: FetchSwapRouteConfig): Promise<SwapResult>;
|
|
54
|
+
export default fetchSwapRoute;
|
|
55
|
+
//# sourceMappingURL=FetchSwapRoute.d.ts.map
|
|
@@ -0,0 +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;CACzB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,WAAW,EACpB,MAAM,GAAE,oBAAyB,GAChC,OAAO,CAAC,UAAU,CAAC,CAoCrB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,KAAK,CAAC;IAAE,OAAO,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,oBAAoB,CAAA;CAAE,CAAC,GACnE,OAAO,CAAC,KAAK,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,UAAU,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAyBzE;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,KAAK,EACf,QAAQ,EAAE,KAAK,EACf,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,oBAAyB,GAChC,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export declare const BITZY_QUERY_ABI: readonly [{
|
|
2
|
+
readonly inputs: readonly [{
|
|
3
|
+
readonly internalType: "uint256";
|
|
4
|
+
readonly name: "srcAmount";
|
|
5
|
+
readonly type: "uint256";
|
|
6
|
+
}, {
|
|
7
|
+
readonly internalType: "bytes";
|
|
8
|
+
readonly name: "encodedRoutes";
|
|
9
|
+
readonly type: "bytes";
|
|
10
|
+
}, {
|
|
11
|
+
readonly internalType: "uint256";
|
|
12
|
+
readonly name: "parts";
|
|
13
|
+
readonly type: "uint256";
|
|
14
|
+
}];
|
|
15
|
+
readonly name: "splitQuery";
|
|
16
|
+
readonly outputs: readonly [{
|
|
17
|
+
readonly components: readonly [{
|
|
18
|
+
readonly internalType: "uint256";
|
|
19
|
+
readonly name: "amountOut";
|
|
20
|
+
readonly type: "uint256";
|
|
21
|
+
}, {
|
|
22
|
+
readonly internalType: "uint256";
|
|
23
|
+
readonly name: "bestIndex";
|
|
24
|
+
readonly type: "uint256";
|
|
25
|
+
}];
|
|
26
|
+
readonly internalType: "struct BitzyQueryV2.OneRoute";
|
|
27
|
+
readonly name: "";
|
|
28
|
+
readonly type: "tuple";
|
|
29
|
+
}, {
|
|
30
|
+
readonly components: readonly [{
|
|
31
|
+
readonly internalType: "uint256[]";
|
|
32
|
+
readonly name: "distribution";
|
|
33
|
+
readonly type: "uint256[]";
|
|
34
|
+
}, {
|
|
35
|
+
readonly internalType: "uint256";
|
|
36
|
+
readonly name: "amountOut";
|
|
37
|
+
readonly type: "uint256";
|
|
38
|
+
}];
|
|
39
|
+
readonly internalType: "struct BitzyQueryV2.SplitRoute";
|
|
40
|
+
readonly name: "";
|
|
41
|
+
readonly type: "tuple";
|
|
42
|
+
}];
|
|
43
|
+
readonly stateMutability: "nonpayable";
|
|
44
|
+
readonly type: "function";
|
|
45
|
+
}];
|
|
46
|
+
//# sourceMappingURL=Abis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Abis.d.ts","sourceRoot":"","sources":["../../src/constants/Abis.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2DlB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Address } from "viem";
|
|
2
|
+
import { ChainWrap, LiquiditySourcesConfig } from "../types";
|
|
3
|
+
export declare const DEX_INTERFACE: {
|
|
4
|
+
readonly V2: 0;
|
|
5
|
+
readonly V3: 1;
|
|
6
|
+
};
|
|
7
|
+
export declare const USER_TARGET: Address;
|
|
8
|
+
export declare const ROUTER_TARGET: Address;
|
|
9
|
+
export declare const DEFAULT_PART_COUNT = 5;
|
|
10
|
+
export declare const DEFAULT_TIMEOUT = 30000;
|
|
11
|
+
export declare const DEFAULT_API_BASE_URL = "https://api-public.bitzy.app";
|
|
12
|
+
export declare const DEX_ROUTERS: ChainWrap<Record<string, Address>>;
|
|
13
|
+
export declare const CONTRACT_ADDRESSES: ChainWrap<{
|
|
14
|
+
factoryAddress: Address;
|
|
15
|
+
v3FactoryAddress: Address;
|
|
16
|
+
v3PositionManagerAddress: Address;
|
|
17
|
+
v3WalletHelperAddress: Address;
|
|
18
|
+
routerAddress: Address;
|
|
19
|
+
aggregatorAddress: Address;
|
|
20
|
+
otcAddress: Address;
|
|
21
|
+
memeTokenGenerator: Address;
|
|
22
|
+
bitzyQueryAddress: Address;
|
|
23
|
+
wrappedAddress: Address;
|
|
24
|
+
nativeAddress: Address;
|
|
25
|
+
gasLimit: bigint;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const LIQUIDITY_SOURCES: ChainWrap<LiquiditySourcesConfig>;
|
|
28
|
+
export declare const getLiquiditySources: (chainId: number) => LiquiditySourcesConfig;
|
|
29
|
+
export declare const getContractAddresses: (chainId: number) => {
|
|
30
|
+
factoryAddress: Address;
|
|
31
|
+
v3FactoryAddress: Address;
|
|
32
|
+
v3PositionManagerAddress: Address;
|
|
33
|
+
v3WalletHelperAddress: Address;
|
|
34
|
+
routerAddress: Address;
|
|
35
|
+
aggregatorAddress: Address;
|
|
36
|
+
otcAddress: Address;
|
|
37
|
+
memeTokenGenerator: Address;
|
|
38
|
+
bitzyQueryAddress: Address;
|
|
39
|
+
wrappedAddress: Address;
|
|
40
|
+
nativeAddress: Address;
|
|
41
|
+
gasLimit: bigint;
|
|
42
|
+
};
|
|
43
|
+
export declare const getDexRouters: (chainId: number) => Record<string, `0x${string}`>;
|
|
44
|
+
export declare const DEFAULT_NETWORKS: ChainWrap<{
|
|
45
|
+
factoryAddress: Address;
|
|
46
|
+
v3FactoryAddress: Address;
|
|
47
|
+
v3PositionManagerAddress: Address;
|
|
48
|
+
v3WalletHelperAddress: Address;
|
|
49
|
+
routerAddress: Address;
|
|
50
|
+
aggregatorAddress: Address;
|
|
51
|
+
otcAddress: Address;
|
|
52
|
+
memeTokenGenerator: Address;
|
|
53
|
+
bitzyQueryAddress: Address;
|
|
54
|
+
wrappedAddress: Address;
|
|
55
|
+
nativeAddress: Address;
|
|
56
|
+
gasLimit: bigint;
|
|
57
|
+
}>;
|
|
58
|
+
export declare const DEX_ROUTER: Record<string, `0x${string}`>;
|
|
59
|
+
export declare const API_ENDPOINTS: {
|
|
60
|
+
readonly PATH_V3: "/api/sdk/bestpath/split";
|
|
61
|
+
readonly ASSET_MINIMUM: "/api/sdk/asset/minimum";
|
|
62
|
+
};
|
|
63
|
+
export declare const ERROR_CODES: {
|
|
64
|
+
readonly INVALID_TOKENS: "INVALID_TOKENS";
|
|
65
|
+
readonly INVALID_AMOUNT: "INVALID_AMOUNT";
|
|
66
|
+
readonly NETWORK_NOT_SUPPORTED: "NETWORK_NOT_SUPPORTED";
|
|
67
|
+
readonly API_ERROR: "API_ERROR";
|
|
68
|
+
readonly QUERY_ERROR: "QUERY_ERROR";
|
|
69
|
+
readonly INSUFFICIENT_LIQUIDITY: "INSUFFICIENT_LIQUIDITY";
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,oBAAoB,GAAI,SAAS,MAAM;oBAlElC,OAAO;sBACL,OAAO;8BACC,OAAO;2BACV,OAAO;mBACf,OAAO;uBACH,OAAO;gBACd,OAAO;wBACC,OAAO;uBACR,OAAO;oBACV,OAAO;mBACR,OAAO;cACZ,MAAM;CAyDjB,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,kCAE5C,CAAC;AAGF,eAAO,MAAM,gBAAgB;oBA3EX,OAAO;sBACL,OAAO;8BACC,OAAO;2BACV,OAAO;mBACf,OAAO;uBACH,OAAO;gBACd,OAAO;wBACC,OAAO;uBACR,OAAO;oBACV,OAAO;mBACR,OAAO;cACZ,MAAM;EAgEgC,CAAC;AACnD,eAAO,MAAM,UAAU,+BAA0B,CAAC;AAGlD,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AAGX,eAAO,MAAM,WAAW;;;;;;;CAOd,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Token, UseSwapV3RoutesConfig } from "../types";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
export interface UseSwapV3RoutesReturn {
|
|
4
|
+
routes: any[][];
|
|
5
|
+
distributions: number[];
|
|
6
|
+
amountOutRoutes: any[];
|
|
7
|
+
amountOutBN: BigNumber;
|
|
8
|
+
amountInParts: any[];
|
|
9
|
+
fetchRoute: () => Promise<void>;
|
|
10
|
+
isLoading: boolean;
|
|
11
|
+
isAmountOutError: boolean;
|
|
12
|
+
isFirstFetch: boolean;
|
|
13
|
+
isWrap?: "wrap" | "unwrap";
|
|
14
|
+
error: string | null;
|
|
15
|
+
clearError: () => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Hot React Hook for Bitzy Swap V3 Routes
|
|
19
|
+
*
|
|
20
|
+
* Provides real-time swap route finding with automatic updates and intelligent routing optimization.
|
|
21
|
+
*
|
|
22
|
+
* ## Key Features:
|
|
23
|
+
*
|
|
24
|
+
* ### Intelligent partCount Logic:
|
|
25
|
+
* - **High-value tokens** (BTC, ETH, USDC, USDT): Uses `partCount = 5` for optimal execution
|
|
26
|
+
* - **Low-value tokens** (meme tokens, small caps): Uses `partCount = 1` for simplicity
|
|
27
|
+
*
|
|
28
|
+
* ### Benefits:
|
|
29
|
+
* - **BTC/ETH swaps**: Use 5 routes for optimal execution and better pricing
|
|
30
|
+
* - **Meme token swaps**: Use 1 route for simplicity and lower gas costs
|
|
31
|
+
* - **Stablecoin swaps**: Use 5 routes for better price discovery
|
|
32
|
+
* - **Easy to extend**: Just add more addresses to the high-value list
|
|
33
|
+
*
|
|
34
|
+
* ### Important Exceptions:
|
|
35
|
+
* **Pair liquidity matters more than token value!**
|
|
36
|
+
* - BTC-X pair with $100 liquidity → 5 parts for $1000 = 50% impact per part
|
|
37
|
+
* - USDC-X pair with $100,000 liquidity → 5 parts for $1000 = 1% impact per part
|
|
38
|
+
*
|
|
39
|
+
* ### User Control:
|
|
40
|
+
* - **Online mode**: Use `useOnlinePartCount: true` for automatic pair liquidity detection
|
|
41
|
+
* - **Offline mode**: Override with `forcePartCount` parameter (ignored when online mode is enabled)
|
|
42
|
+
* - Customize `defaultPartCount` for high-value tokens
|
|
43
|
+
* - **Best practice**: Use online mode for accurate results, offline mode for speed
|
|
44
|
+
*
|
|
45
|
+
* ## Usage Examples:
|
|
46
|
+
*
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Minimal usage with defaults
|
|
49
|
+
* const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId);
|
|
50
|
+
* // Uses: apiBaseUrl from DEFAULT_API_BASE_URL, apiKey from NEXT_PUBLIC_BITZY_API_KEY env var or fallback
|
|
51
|
+
*
|
|
52
|
+
* // With custom API URL
|
|
53
|
+
* const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
|
|
54
|
+
* apiBaseUrl: "https://api-public.bitzy.app",
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // With custom API key
|
|
58
|
+
* const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
|
|
59
|
+
* apiKey: "your-custom-api-key",
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // With custom liquidity sources
|
|
63
|
+
* const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
|
|
64
|
+
* apiBaseUrl: "https://api-public.bitzy.app",
|
|
65
|
+
* types: [2], // Only V3
|
|
66
|
+
* enabledSources: [1], // Only BITZY
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // With custom address config
|
|
70
|
+
* const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
|
|
71
|
+
* apiBaseUrl: "https://api-public.bitzy.app",
|
|
72
|
+
* config: addressConfig,
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* // Force specific partCount
|
|
76
|
+
* const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
|
|
77
|
+
* apiBaseUrl: "https://api-public.bitzy.app",
|
|
78
|
+
* config: addressConfig,
|
|
79
|
+
* forcePartCount: 3, // Always use 3 routes
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* // Custom default for high-value tokens
|
|
83
|
+
* const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
|
|
84
|
+
* apiBaseUrl: "https://api-public.bitzy.app",
|
|
85
|
+
* config: addressConfig,
|
|
86
|
+
* defaultPartCount: 7, // High-value tokens use 7 routes instead of 5
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* // CRITICAL: Check pair liquidity first!
|
|
90
|
+
* // Low liquidity pair - force single route
|
|
91
|
+
* const lowLiquidityResult = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
|
|
92
|
+
* apiBaseUrl: "https://api-public.bitzy.app",
|
|
93
|
+
* config: addressConfig,
|
|
94
|
+
* forcePartCount: 1, // Avoid splitting in low liquidity pairs
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* // High liquidity pair - safe to use multiple routes
|
|
98
|
+
* const highLiquidityResult = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
|
|
99
|
+
* apiBaseUrl: "https://api-public.bitzy.app",
|
|
100
|
+
* config: addressConfig,
|
|
101
|
+
* forcePartCount: 5, // Safe to split in high liquidity pairs
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare const useSwapV3Routes: (srcToken: Token | undefined | null, dstToken: Token | undefined | null, amountIn: string, chainId: number, config?: UseSwapV3RoutesConfig) => UseSwapV3RoutesReturn;
|
|
106
|
+
export default useSwapV3Routes;
|
|
107
|
+
//# sourceMappingURL=useSwapV3Routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSwapV3Routes.d.ts","sourceRoot":"","sources":["../../src/hooks/useSwapV3Routes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAIL,qBAAqB,EAEtB,MAAM,UAAU,CAAC;AAIlB,OAAO,SAAS,MAAM,cAAc,CAAC;AAcrC,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC;IAChB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,eAAe,EAAE,GAAG,EAAE,CAAC;IACvB,WAAW,EAAE,SAAS,CAAC;IACvB,aAAa,EAAE,GAAG,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC3B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuFG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAU,KAAK,GAAG,SAAS,GAAG,IAAI,EAClC,UAAU,KAAK,GAAG,SAAS,GAAG,IAAI,EAClC,UAAU,MAAM,EAChB,SAAS,MAAM,EACf,SAAQ,qBAA0B,KACjC,qBAsXF,CAAC;AAGF,eAAe,eAAe,CAAC"}
|