@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,259 @@
1
+ import { Address, PublicClient } from "viem";
2
+ import BigNumber from "bignumber.js";
3
+ export interface UseSwapV3RoutesAddressConfig {
4
+ /**
5
+ * Address of the Bitzy router contract
6
+ * Used for executing swap transactions
7
+ * @example "0xA5E0AE4e5103dc71cA290AA3654830442357A489"
8
+ */
9
+ routerAddress: Address;
10
+ /**
11
+ * Address of the Bitzy query contract
12
+ * Used for fetching swap routes and pricing data
13
+ * @example "0x5b5079587501Bd85d3CDf5bFDf299f4eaAe98c23"
14
+ */
15
+ bitzyQueryAddress: Address;
16
+ /**
17
+ * Address of the wrapped native token (e.g., pBTC on Botanix)
18
+ * Used for handling native token swaps
19
+ * @example "0x0D2437F93Fed6EA64Ef01cCde385FB1263910C56"
20
+ */
21
+ wrappedAddress: Address;
22
+ /**
23
+ * Address representing the native token (ETH/BTC)
24
+ * Standard address used across all networks for native tokens
25
+ * @example "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
26
+ */
27
+ nativeAddress: Address;
28
+ }
29
+ export interface UseSwapV3RoutesConfig {
30
+ /**
31
+ * Base URL for the Bitzy API
32
+ * @default "https://api-public.bitzy.app"
33
+ * @example "https://api-public.bitzy.app"
34
+ */
35
+ apiBaseUrl?: string;
36
+ /**
37
+ * API key for authentication (optional)
38
+ * Used for premium features and rate limiting
39
+ * @example "your-api-key-here"
40
+ */
41
+ apiKey?: string;
42
+ /**
43
+ * Contract addresses configuration for the specific network
44
+ * Contains router, query, wrapped, and native token addresses
45
+ */
46
+ config?: UseSwapV3RoutesAddressConfig;
47
+ /**
48
+ * Default number of routes to split large swaps into
49
+ * Higher values provide better execution but increase gas costs
50
+ * @default 5
51
+ * @example 5
52
+ */
53
+ defaultPartCount?: number;
54
+ /**
55
+ * Request timeout in milliseconds
56
+ * @default 30000 (30 seconds)
57
+ * @example 30000
58
+ */
59
+ timeout?: number;
60
+ /**
61
+ * Additional HTTP headers to include with API requests
62
+ * @example { "authen-key": "token" }
63
+ */
64
+ headers?: Record<string, string>;
65
+ /**
66
+ * Interval in milliseconds for automatic route refresh
67
+ * Set to 0 to disable automatic refresh
68
+ * @default 10000 (10 seconds)
69
+ * @example 10000
70
+ */
71
+ refreshInterval?: number;
72
+ /**
73
+ * Viem PublicClient instance for blockchain interactions
74
+ * Used for contract calls and blockchain state queries
75
+ * @example publicClient from useAccount() hook
76
+ */
77
+ publicClient?: PublicClient;
78
+ /**
79
+ * Array of liquidity source types to include
80
+ * 1 = V2, 2 = V3
81
+ * @default [1, 2] (both V2 and V3)
82
+ * @example [2] (V3 only)
83
+ */
84
+ types?: number[];
85
+ /**
86
+ * Array of enabled liquidity sources
87
+ * 1 = BITZY, 2 = Other sources
88
+ * @default [1] (BITZY only)
89
+ * @example [1, 2] (BITZY and other sources)
90
+ */
91
+ enabledSources?: number[];
92
+ /**
93
+ * Override partCount calculation logic (offline mode only)
94
+ * - If provided, this value will be used instead of automatic calculation
95
+ * - **IGNORED when useOnlinePartCount is true** (best practice)
96
+ * - If not provided, uses intelligent address-based logic:
97
+ * - High-value tokens (BTC, ETH, USDC, USDT): partCount = 5 (better routing)
98
+ * - Low-value tokens (meme tokens, small caps): partCount = 1 (simpler routing)
99
+ *
100
+ * IMPORTANT EXCEPTIONS & CONCERNS:
101
+ *
102
+ * ## Pair Liquidity Impact:
103
+ * Even high-value tokens can cause issues in low-liquidity pairs:
104
+ *
105
+ * ### Problem Examples:
106
+ * - **BTC-X pair** with only $100 liquidity → Using 5 parts for $1000 swap = 50% impact per part
107
+ * - **USDC-X pair** with $100,000 liquidity → Using 5 parts for $1000 swap = 1% impact per part
108
+ *
109
+ * ### When to Override (offline mode only):
110
+ * ```typescript
111
+ * // Low liquidity pair - force single route
112
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
113
+ * ...config,
114
+ * useOnlinePartCount: false, // Disable online mode
115
+ * forcePartCount: 1, // Avoid splitting in low liquidity
116
+ * });
117
+ *
118
+ * // High liquidity pair - allow more routes
119
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
120
+ * ...config,
121
+ * useOnlinePartCount: false, // Disable online mode
122
+ * forcePartCount: 5, // Safe to split in high liquidity
123
+ * });
124
+ * ```
125
+ *
126
+ * ### Concerns to Consider:
127
+ * - **Slippage**: Too many parts in low liquidity = higher slippage
128
+ * - **Gas costs**: More routes = higher transaction costs
129
+ * - **Execution time**: More routes = longer execution
130
+ * - **Price impact**: Each part affects price, compounding impact
131
+ *
132
+ * ### Recommended Approach:
133
+ * 1. **Use useOnlinePartCount: true** for automatic pair liquidity detection
134
+ * 2. **Use forcePartCount** only when online mode is disabled
135
+ * 3. **Monitor slippage** and adjust accordingly
136
+ */
137
+ forcePartCount?: number;
138
+ /**
139
+ * Use online API to determine optimal partCount based on real pair liquidity
140
+ * - If true, calls API to get actual pair liquidity and calculates optimal partCount
141
+ * - If false or undefined, uses offline address-based logic
142
+ * - Falls back to offline logic if API call fails
143
+ * - Uses sensible defaults: 5% max impact, $10,000 min liquidity
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * // Use online API for accurate partCount calculation
148
+ * const result = useSwapV3Routes(srcToken, dstToken, amountIn, chainId, {
149
+ * ...config,
150
+ * useOnlinePartCount: true, // Get real-time pair liquidity data
151
+ * });
152
+ * ```
153
+ */
154
+ useOnlinePartCount?: boolean;
155
+ }
156
+ export type BN = BigNumber;
157
+ export { BigNumber };
158
+ export declare const ensureBigNumber: (value: any) => BigNumber;
159
+ export declare const isBigNumber: (value: any) => value is BigNumber;
160
+ export interface SwapV3AddressConfig extends UseSwapV3RoutesAddressConfig {
161
+ /**
162
+ * Gas limit for transactions
163
+ * @default BigInt(50_000_000_000)
164
+ * @example BigInt(50_000_000_000)
165
+ */
166
+ gasLimit?: bigint;
167
+ /**
168
+ * Gas price for transactions (optional)
169
+ * If not provided, uses network default
170
+ * @example BigInt(20_000_000_000) // 20 gwei
171
+ */
172
+ gasPrice?: bigint;
173
+ }
174
+ export interface Token {
175
+ address: Address;
176
+ symbol: string;
177
+ name: string;
178
+ decimals: number;
179
+ logoURI?: string;
180
+ chainId?: number;
181
+ }
182
+ export interface SwapRoute {
183
+ routerAddress: Address;
184
+ lpAddress: Address;
185
+ fromToken: Address;
186
+ toToken: Address;
187
+ from: Address;
188
+ to: Address;
189
+ part: string;
190
+ amountAfterFee: string;
191
+ dexInterface: number;
192
+ }
193
+ export interface SwapResult {
194
+ routes: SwapRoute[][];
195
+ distributions: number[];
196
+ amountOutRoutes: BigNumber[];
197
+ amountOutBN: BigNumber;
198
+ amountInParts: BigNumber[];
199
+ isAmountOutError: boolean;
200
+ isWrap?: "wrap" | "unwrap";
201
+ }
202
+ export interface SwapOptions {
203
+ amountIn: string;
204
+ srcToken: Token;
205
+ dstToken: Token;
206
+ chainId: number;
207
+ partCount?: number;
208
+ liquiditySources?: LiquiditySource[];
209
+ types?: number[];
210
+ enabledSources?: number[];
211
+ /**
212
+ * Force a specific partCount, overriding intelligent calculation
213
+ * - If provided, this value will be used instead of automatic calculation
214
+ * - If not provided, uses intelligent address-based logic:
215
+ * - High-value tokens (BTC, ETH, USDC, USDT): partCount = 5 (better routing)
216
+ * - Low-value tokens (meme tokens, small caps): partCount = 1 (simpler routing)
217
+ */
218
+ forcePartCount?: number;
219
+ }
220
+ export interface LiquiditySource {
221
+ type: "V2" | "V3";
222
+ source: string;
223
+ enabled: boolean;
224
+ }
225
+ export interface NetworkConfig {
226
+ routerAddress: Address;
227
+ bitzyQueryAddress: Address;
228
+ wrappedAddress: Address;
229
+ nativeAddress: Address;
230
+ }
231
+ export interface PathV3Response {
232
+ data: {
233
+ hops: any[];
234
+ validPath: any[];
235
+ };
236
+ }
237
+ export declare class SwapError extends Error {
238
+ code: string;
239
+ details?: any;
240
+ constructor(options: {
241
+ message: string;
242
+ code: string;
243
+ details?: any;
244
+ });
245
+ }
246
+ export type ChainWrap<T> = {
247
+ [chainId: number]: T;
248
+ };
249
+ export interface LiquiditySourcesConfig {
250
+ types: number[];
251
+ enabledSources: number[];
252
+ }
253
+ export interface SDKConfig {
254
+ networks: Record<number, NetworkConfig>;
255
+ defaultPartCount: number;
256
+ apiBaseUrl?: string;
257
+ timeout?: number;
258
+ }
259
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAC7C,OAAO,SAAS,MAAM,cAAc,CAAC;AAGrC,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;;;OAIG;IACH,iBAAiB,EAAE,OAAO,CAAC;IAE3B;;;;OAIG;IACH,cAAc,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,MAAM,CAAC,EAAE,4BAA4B,CAAC;IAEtC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAE5B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IAEjB;;;;;OAKG;IACH,cAAc,CAAC,EAAE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MAAM,GAAG,CAAC,CAAC;CACtB,CAAC;AAGF,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAGD,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACxC,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1,101 @@
1
+ import { Token, ChainWrap } from "../types";
2
+ /**
3
+ * Clear the minimum amounts cache
4
+ * Useful for testing or when you need fresh data immediately
5
+ */
6
+ declare function clearMinimumAmountsCache(): void;
7
+ /**
8
+ * High-value tokens that benefit from multi-route optimization
9
+ * These tokens typically have high liquidity and benefit from route splitting
10
+ * Network-specific token addresses using ChainWrap pattern
11
+ */
12
+ declare const HIGH_VALUE_TOKENS: ChainWrap<string[]>;
13
+ /**
14
+ * Check if a token is considered high-value based on its address and chain
15
+ * @param token - The token to check
16
+ * @param chainId - The chain ID to get network-specific tokens
17
+ * @returns true if the token is high-value, false otherwise
18
+ */
19
+ export declare function isHighValueToken(token: Token | undefined | null, chainId: number): boolean;
20
+ /**
21
+ * Get partCount based on token pair addresses (offline logic)
22
+ * This function uses hardcoded address-based logic to determine optimal partCount
23
+ * Considers both tokens in the pair for better decision making
24
+ *
25
+ * IMPORTANT: This is a simplified approach that doesn't consider actual pair liquidity!
26
+ * For more accurate results, use getPartCountOnline() which checks actual pair liquidity.
27
+ *
28
+ * @param srcToken - The source token
29
+ * @param dstToken - The destination token
30
+ * @param chainId - The chain ID to get network-specific tokens
31
+ * @param defaultPartCount - Default partCount for high-value pairs (default: 5)
32
+ * @returns partCount: 5 for high-value pairs, 1 for others
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // High-value pair (BTC-USDC) → returns 5
37
+ * const highValuePartCount = getPartCountOffline(btcToken, usdcToken, 3637, 5);
38
+ *
39
+ * // Low-value pair (BTC-MEME) → returns 1
40
+ * const lowValuePartCount = getPartCountOffline(btcToken, memeToken, 3637, 5);
41
+ * ```
42
+ */
43
+ export declare function getPartCountOffline(srcToken: Token | undefined | null, dstToken: Token | undefined | null, chainId: number, defaultPartCount?: number): number;
44
+ /**
45
+ * Get partCount using online API data (minimum amount-based)
46
+ * Checks if the swap amount meets the minimum threshold for multi-route optimization
47
+ *
48
+ * @param srcToken - Source token
49
+ * @param dstToken - Destination token
50
+ * @param amountIn - Input amount
51
+ * @param chainId - Chain ID
52
+ * @param apiBaseUrl - API base URL
53
+ * @param apiKey - Optional API key
54
+ * @returns Promise<number> - partCount (5 if amount >= minimum for both tokens, otherwise fallback)
55
+ */
56
+ export declare function getPartCountOnline(srcToken: Token, dstToken: Token, amountIn: string, chainId: number, apiBaseUrl: string, apiKey?: string, fallbackPartCount?: number): Promise<number>;
57
+ /**
58
+ * Get partCount with fallback strategy
59
+ * Tries online API first, falls back to offline logic if API fails
60
+ * Uses sensible defaults: 5% max impact, $10,000 min liquidity
61
+ *
62
+ * @param srcToken - The source token
63
+ * @param dstToken - The destination token
64
+ * @param amountIn - The swap amount
65
+ * @param chainId - The chain ID
66
+ * @param apiBaseUrl - The API base URL
67
+ * @param fallbackPartCount - PartCount to use if API fails (default: 5)
68
+ * @returns Promise<number> - Optimal partCount
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * // Try online first, fallback to offline
73
+ * const partCount = await getPartCountWithFallback(
74
+ * srcToken,
75
+ * dstToken,
76
+ * amountIn,
77
+ * chainId,
78
+ * apiBaseUrl,
79
+ * 5 // fallback partCount
80
+ * );
81
+ * ```
82
+ */
83
+ export declare function getPartCountWithFallback(srcToken: Token, dstToken: Token, amountIn: string, chainId: number, apiBaseUrl: string, fallbackPartCount?: number, apiKey?: string): Promise<number>;
84
+ /**
85
+ * Calculate price impact for a given swap
86
+ * @param swapAmount - The swap amount in USD
87
+ * @param pairLiquidity - The pair liquidity in USD
88
+ * @param partCount - The number of parts to split the swap
89
+ * @returns The price impact percentage
90
+ */
91
+ export declare function calculatePriceImpact(swapAmount: number, pairLiquidity: number, partCount: number): number;
92
+ /**
93
+ * Determine optimal partCount based on price impact thresholds
94
+ * @param swapAmount - The swap amount in USD
95
+ * @param pairLiquidity - The pair liquidity in USD
96
+ * @param maxImpactThreshold - Maximum acceptable impact per part (default: 5%)
97
+ * @returns Optimal partCount (1 or 5)
98
+ */
99
+ export declare function getOptimalPartCount(swapAmount: number, pairLiquidity: number, maxImpactThreshold?: number): number;
100
+ export { HIGH_VALUE_TOKENS, clearMinimumAmountsCache };
101
+ //# sourceMappingURL=PartCount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PartCount.d.ts","sourceRoot":"","sources":["../../src/utils/PartCount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAyD5C;;;GAGG;AACH,iBAAS,wBAAwB,IAAI,IAAI,CAGxC;AAED;;;;GAIG;AACH,QAAA,MAAM,iBAAiB,EAAE,SAAS,CAAC,MAAM,EAAE,CAiB1C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,EAC/B,OAAO,EAAE,MAAM,GACd,OAAO,CAST;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,EAClC,QAAQ,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,EAClC,OAAO,EAAE,MAAM,EACf,gBAAgB,GAAE,MAAU,GAC3B,MAAM,CAOR;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,KAAK,EACf,QAAQ,EAAE,KAAK,EACf,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,iBAAiB,GAAE,MAAU,GAC5B,OAAO,CAAC,MAAM,CAAC,CA8CjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,KAAK,EACf,QAAQ,EAAE,KAAK,EACf,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,iBAAiB,GAAE,MAAU,EAC7B,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,GAChB,MAAM,CAKR;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,kBAAkB,GAAE,MAAU,GAC7B,MAAM,CAQR;AAGD,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,CAAC"}
@@ -0,0 +1,68 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { Address } from "viem";
3
+ import { Token } from "../types";
4
+ /**
5
+ * Convert token amount from human readable format to wei
6
+ * @param amount - Human readable amount (e.g., "1.5")
7
+ * @param decimals - Token decimals
8
+ * @returns BigNumber representation in wei
9
+ */
10
+ export declare function fromTokenAmount(amount: string, decimals: number): BigNumber;
11
+ /**
12
+ * Convert token amount from wei to human readable format
13
+ * @param amount - Amount in wei
14
+ * @param decimals - Token decimals
15
+ * @returns Human readable amount string
16
+ */
17
+ export declare function toTokenAmount(amount: BigNumber | string, decimals: number): string;
18
+ /**
19
+ * Check if a token is native (ETH, BNB, etc.)
20
+ * @param token - Token to check
21
+ * @param nativeAddress - Native token address for the network
22
+ * @returns boolean
23
+ */
24
+ export declare function isNativeToken(token: Token, nativeAddress: Address): boolean;
25
+ /**
26
+ * Check if a token is wrapped (WETH, WBNB, etc.)
27
+ * @param token - Token to check
28
+ * @param wrappedAddress - Wrapped token address for the network
29
+ * @returns boolean
30
+ */
31
+ export declare function isWrappedToken(token: Token, wrappedAddress: Address): boolean;
32
+ /**
33
+ * Validate token addresses
34
+ * @param srcToken - Source token
35
+ * @param dstToken - Destination token
36
+ * @returns boolean
37
+ */
38
+ export declare function validateTokens(srcToken: Token, dstToken: Token): boolean;
39
+ /**
40
+ * Validate amount input
41
+ * @param amount - Amount to validate
42
+ * @returns boolean
43
+ */
44
+ export declare function validateAmount(amount: string): boolean;
45
+ /**
46
+ * Calculate optimal part count of a route based on amount and price
47
+ * @param amount - Input amount
48
+ * @param price - Token price in USD
49
+ * @param partCount - Default part count of a route
50
+ * @returns number
51
+ */
52
+ export declare function calculatePartCount(amount: string, price: number, partCount?: number): number;
53
+ /**
54
+ * Format error message
55
+ * @param error - Error object or string
56
+ * @returns Formatted error string
57
+ */
58
+ export declare function formatError(error: any): string;
59
+ /**
60
+ * Debounce function
61
+ * @param func - Function to debounce
62
+ * @param wait - Wait time in milliseconds
63
+ * @returns Debounced function with cancel method
64
+ */
65
+ export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number): ((...args: Parameters<T>) => void) & {
66
+ cancel: () => void;
67
+ };
68
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAK3E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,SAAS,GAAG,MAAM,EAC1B,QAAQ,EAAE,MAAM,GACf,MAAM,CAGR;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,GAAG,OAAO,CAE3E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,GAAG,OAAO,CAE7E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,GAAG,OAAO,CASxE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAMtD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAAW,GACrB,MAAM,CAGR;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,CAW9C;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,GACX,CAAC,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAa7D"}
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@bitzy-app/bitzy-sdk",
3
+ "version": "0.0.1",
4
+ "description": "Bitzy Swap V3 Routes SDK for frontend and backend applications",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.esm.js",
8
+ "types": "dist/index.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "scripts": {
15
+ "build": "rollup -c",
16
+ "dev": "rollup -c -w",
17
+ "clean": "rimraf dist",
18
+ "prepublishOnly": "npm run clean && npm run build",
19
+ "test": "jest",
20
+ "lint": "eslint src --ext .ts,.tsx",
21
+ "type-check": "tsc --noEmit"
22
+ },
23
+ "keywords": [
24
+ "bitzy",
25
+ "swap",
26
+ "defi",
27
+ "ethereum",
28
+ "botanix",
29
+ "v3",
30
+ "liquidity",
31
+ "routing"
32
+ ],
33
+ "author": "Bitzy Team",
34
+ "license": "MIT",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/bitzy-app/bitzy-sdk"
38
+ },
39
+ "dependencies": {
40
+ "bignumber.js": "^9.1.2",
41
+ "lodash": "^4.17.21",
42
+ "viem": "^2.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@rollup/plugin-commonjs": "^25.0.0",
46
+ "@rollup/plugin-node-resolve": "^15.0.0",
47
+ "@rollup/plugin-typescript": "^11.0.0",
48
+ "@rollup/plugin-terser": "^0.4.4",
49
+ "@types/jest": "^30.0.0",
50
+ "@types/lodash": "^4.14.202",
51
+ "@types/node": "^20.0.0",
52
+ "@types/react": "^18.0.0",
53
+ "eslint": "^8.0.0",
54
+ "jest": "^29.7.0",
55
+ "rimraf": "^6.0.1",
56
+ "rollup": "^4.0.0",
57
+ "rollup-plugin-dts": "^6.0.0",
58
+ "ts-jest": "^29.4.1",
59
+ "tslib": "^2.6.0",
60
+ "typescript": "^5.0.0"
61
+ },
62
+ "peerDependencies": {
63
+ "viem": "^2.0.0",
64
+ "react": ">=16.8.0"
65
+ },
66
+ "engines": {
67
+ "node": ">=18.0.0"
68
+ },
69
+ "publishConfig": {
70
+ "access": "public",
71
+ "registry": "https://registry.npmjs.org/"
72
+ },
73
+ "homepage": "https://github.com/bitzy/bitzy-swap-sdk#readme",
74
+ "bugs": {
75
+ "url": "https://github.com/bitzy/bitzy-swap-sdk/issues"
76
+ }
77
+ }