@rhea-finance/cross-chain-aggregation-dex 0.1.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/README.md ADDED
@@ -0,0 +1,653 @@
1
+ # @rhea-finance/cross-chain-aggregation-dex
2
+
3
+ A powerful TypeScript SDK for cross-chain DEX aggregation and routing on NEAR blockchain. This SDK provides intelligent routing across multiple DEXs, automatic token registration, pre-swap handling for non-bluechip tokens, and seamless integration with NearIntents bridge protocol for cross-chain token swaps.
4
+
5
+ ## Overview
6
+
7
+ This SDK offers two router implementations for different use cases:
8
+
9
+ - **NearSmartRouter (V1)**: Simple routing via FindPath API and REF Finance execution. Best for straightforward swaps without complex recipient handling.
10
+ - **AggregateDexRouter (V2)**: Advanced multi-DEX aggregation with automatic registration handling. Supports complex scenarios with multiple recipients and automatic token registration.
11
+
12
+ Both routers support optimal path finding, slippage protection, and can be combined with NearIntents for cross-chain functionality.
13
+
14
+ ## Features
15
+
16
+ - 🔄 **DEX Aggregation Routing**: Automatically finds optimal swap paths across multiple DEXs on NEAR
17
+ - 🚀 **Dual Router Support**: Two router implementations (V1 Simple Router & V2 Aggregate Router) for different use cases
18
+ - 🌉 **Cross-chain Support**: Seamless integration with NearIntents bridge protocol for cross-chain swaps
19
+ - 🔀 **Pre-swap Handling**: Automatically converts non-bluechip tokens to bluechip tokens (USDT/USDC/wNEAR) when needed
20
+ - 🔐 **Auto Registration**: Automatically handles token storage registration for users and contracts
21
+ - 📊 **Multi-Router Comparison**: Compare quotes from multiple routers and select the best one
22
+ - 📦 **Type Safety**: Complete TypeScript type definitions with full IntelliSense support
23
+ - 🔌 **Adapter Pattern**: Flexible adapter interfaces for easy integration with any backend or wallet
24
+ - 🛡️ **Slippage Protection**: Built-in slippage calculation and protection
25
+ - 📝 **Comprehensive Logging**: Configurable logging levels for debugging and monitoring
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ npm install @rhea-finance/cross-chain-aggregation-dex
31
+ # or
32
+ pnpm add @rhea-finance/cross-chain-aggregation-dex
33
+ # or
34
+ yarn add @rhea-finance/cross-chain-aggregation-dex
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ### 1. Create Adapters
40
+
41
+ First, you need to implement adapter interfaces to provide necessary dependencies:
42
+
43
+ ```typescript
44
+ import {
45
+ FindPathAdapter,
46
+ SwapMultiDexPathAdapter,
47
+ IntentsQuotationAdapter,
48
+ NearChainAdapter,
49
+ ConfigAdapter,
50
+ } from "@rhea-finance/cross-chain-aggregation-dex";
51
+
52
+ // FindPath API adapter (for NearSmartRouter V1)
53
+ const findPathAdapter: FindPathAdapter = {
54
+ async findPath(params) {
55
+ const response = await fetch(
56
+ `https://smartrouter.rhea.finance/findPath?${new URLSearchParams({
57
+ amountIn: params.amountIn,
58
+ tokenIn: params.tokenIn,
59
+ tokenOut: params.tokenOut,
60
+ pathDeep: "3",
61
+ slippage: String(params.slippage),
62
+ })}`
63
+ );
64
+ return response.json();
65
+ },
66
+ };
67
+
68
+ // SwapMultiDexPath API adapter (for AggregateDexRouter V2)
69
+ const swapMultiDexPathAdapter: SwapMultiDexPathAdapter = {
70
+ async swapMultiDexPath(params) {
71
+ const response = await fetch(
72
+ `https://smartx.rhea.finance/swapMultiDexPath?${new URLSearchParams({
73
+ amountIn: params.amountIn,
74
+ tokenIn: params.tokenIn,
75
+ tokenOut: params.tokenOut,
76
+ slippage: String(params.slippage),
77
+ pathDeep: "2",
78
+ chainId: "0",
79
+ routerCount: "1",
80
+ skipUnwrapNativeToken: "false",
81
+ user: params.user,
82
+ receiveUser: params.receiveUser,
83
+ })}`
84
+ );
85
+ return response.json();
86
+ },
87
+ };
88
+
89
+ // NearIntents quotation adapter
90
+ const intentsQuotationAdapter: IntentsQuotationAdapter = {
91
+ async quote(params) {
92
+ // Call your NearIntents API
93
+ const response = await fetch("https://your-api.com/intents/quote", {
94
+ method: "POST",
95
+ body: JSON.stringify(params),
96
+ });
97
+ return response.json();
98
+ },
99
+ };
100
+
101
+ // Near chain interaction adapter
102
+ const nearChainAdapter: NearChainAdapter = {
103
+ async call({ transactions }) {
104
+ // Use your Near wallet or RPC to call contracts
105
+ // Return { status: "success", txHash: "...", txHashArr?: [...] }
106
+ },
107
+ async view({ contractId, methodName, args }) {
108
+ // Use your Near RPC to view contract state
109
+ },
110
+ };
111
+
112
+ // Configuration adapter
113
+ const configAdapter: ConfigAdapter = {
114
+ getRefExchangeId: () => "v2.ref-finance.near",
115
+ getWrapNearContractId: () => "wrap.near",
116
+ getFindPathUrl: () => "https://smartrouter.ref.finance",
117
+ getTokenStorageDepositRead: () => "1250000000000000000000",
118
+ getAggregateDexContractId: () => "aggregate-dex-contract.near", // For V2 Router
119
+ };
120
+ ```
121
+
122
+ ### 2. Create Router Instances
123
+
124
+ #### Using NearSmartRouter (V1)
125
+
126
+ ```typescript
127
+ import { NearSmartRouter } from "@rhea-finance/cross-chain-aggregation-dex";
128
+
129
+ const v1Router = new NearSmartRouter({
130
+ findPathAdapter,
131
+ nearChainAdapter,
132
+ configAdapter,
133
+ });
134
+ ```
135
+
136
+ #### Using AggregateDexRouter (V2)
137
+
138
+ ```typescript
139
+ import { AggregateDexRouter } from "@rhea-finance/cross-chain-aggregation-dex";
140
+
141
+ const v2Router = new AggregateDexRouter({
142
+ swapMultiDexPathAdapter,
143
+ nearChainAdapter,
144
+ configAdapter,
145
+ });
146
+ ```
147
+
148
+ ### 3. Get Quote
149
+
150
+ #### Using NearSmartRouter (V1)
151
+
152
+ ```typescript
153
+ import { TokenInfo } from "@rhea-finance/cross-chain-aggregation-dex";
154
+
155
+ const tokenIn: TokenInfo = {
156
+ address: "token-a.near",
157
+ symbol: "TOKENA",
158
+ decimals: 18,
159
+ chain: "near",
160
+ };
161
+
162
+ const tokenOut: TokenInfo = {
163
+ address: "token-b.near",
164
+ symbol: "TOKENB",
165
+ decimals: 18,
166
+ chain: "near",
167
+ };
168
+
169
+ // V1 Router - Simple quote (no recipient required)
170
+ const quote = await v1Router.quote({
171
+ tokenIn,
172
+ tokenOut,
173
+ amountIn: "1000000000000000000", // 1 token (18 decimals)
174
+ slippage: 50, // 0.5% (50 basis points)
175
+ swapType: "EXACT_INPUT",
176
+ });
177
+
178
+ if (quote.success) {
179
+ console.log("Amount out:", quote.amountOut);
180
+ console.log("Min amount out:", quote.minAmountOut);
181
+ console.log("Routes:", quote.routes);
182
+ } else {
183
+ console.error("Quote failed:", quote.error);
184
+ }
185
+ ```
186
+
187
+ #### Using AggregateDexRouter (V2)
188
+
189
+ ```typescript
190
+ // V2 Router - Requires sender and recipient
191
+ const quote = await v2Router.quote({
192
+ tokenIn,
193
+ tokenOut,
194
+ amountIn: "1000000000000000000",
195
+ slippage: 50,
196
+ swapType: "EXACT_INPUT",
197
+ sender: "user.near", // Required for V2
198
+ recipient: "user.near", // Required for V2 (can be same as sender)
199
+ });
200
+
201
+ if (quote.success) {
202
+ console.log("Amount out:", quote.amountOut);
203
+ console.log("Min amount out:", quote.minAmountOut);
204
+ console.log("Router message:", quote.routerMsg);
205
+ console.log("Tokens involved:", quote.tokens);
206
+ console.log("DEXs involved:", quote.dexs);
207
+ } else {
208
+ console.error("Quote failed:", quote.error);
209
+ }
210
+ ```
211
+
212
+ ### 4. Execute Swap
213
+
214
+ #### Using NearSmartRouter (V1)
215
+
216
+ ```typescript
217
+ const result = await v1Router.executeSwap({
218
+ quote,
219
+ recipient: "user.near",
220
+ depositAddress: "deposit.near", // optional, for cross-chain scenarios
221
+ });
222
+
223
+ if (result.success) {
224
+ console.log("Transaction hash:", result.txHash);
225
+ console.log("Transaction hashes:", result.txHashArray);
226
+ } else {
227
+ console.error("Swap failed:", result.error);
228
+ }
229
+ ```
230
+
231
+ #### Using AggregateDexRouter (V2)
232
+
233
+ ```typescript
234
+ // V2 Router - Requires sender and receiveUser (depositAddress)
235
+ const result = await v2Router.executeSwap({
236
+ quote,
237
+ sender: "user.near", // Required for V2
238
+ receiveUser: "deposit.near", // Required for V2 (usually depositAddress)
239
+ recipient: "user.near", // Optional, kept for compatibility
240
+ });
241
+
242
+ if (result.success) {
243
+ console.log("Transaction hash:", result.txHash);
244
+ console.log("Transaction hashes:", result.txHashArray);
245
+ } else {
246
+ console.error("Swap failed:", result.error);
247
+ }
248
+ ```
249
+
250
+ > **Note**: V2 Router automatically fetches a fresh quote using `receiveUser` (depositAddress) during `executeSwap` to ensure correct `routerMsg` and `signature`. You don't need to call `finalizeQuote` manually.
251
+
252
+ ### 5. Complete Quote (DEX Aggregator + NearIntents)
253
+
254
+ The `completeQuote` function integrates DEX aggregation with NearIntents bridge for cross-chain swaps. It automatically handles pre-swaps when needed:
255
+
256
+ ```typescript
257
+ import { completeQuote } from "@rhea-finance/cross-chain-aggregation-dex";
258
+
259
+ const bluechipTokens = {
260
+ USDT: {
261
+ address: "usdt.tether-token.near",
262
+ symbol: "USDT",
263
+ decimals: 6,
264
+ assetId: "nep141:usdt.tether-token.near",
265
+ },
266
+ USDC: {
267
+ address: "17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
268
+ symbol: "USDC",
269
+ decimals: 6,
270
+ assetId: "nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
271
+ },
272
+ NEAR: {
273
+ address: "wrap.near",
274
+ symbol: "wNEAR",
275
+ decimals: 24,
276
+ assetId: "nep141:wrap.near",
277
+ },
278
+ };
279
+
280
+ // Using single router
281
+ const completeQuoteResult = await completeQuote(
282
+ {
283
+ sourceToken: tokenIn,
284
+ targetToken: tokenOut,
285
+ sourceChain: "near",
286
+ targetChain: "bsc",
287
+ amountIn: "1000000000000000000",
288
+ slippage: 50,
289
+ recipient: "0x...", // Target chain address
290
+ refundTo: "user.near",
291
+ },
292
+ {
293
+ intentsQuotationAdapter,
294
+ dexRouter: v1Router, // or v2Router
295
+ bluechipTokens,
296
+ configAdapter,
297
+ currentUserAddress: "user.near", // Required for V2 Router
298
+ }
299
+ );
300
+
301
+ // Using multiple routers (compares and selects best quote)
302
+ const completeQuoteResult = await completeQuote(
303
+ {
304
+ sourceToken: tokenIn,
305
+ targetToken: tokenOut,
306
+ sourceChain: "near",
307
+ targetChain: "bsc",
308
+ amountIn: "1000000000000000000",
309
+ slippage: 50,
310
+ recipient: "0x...",
311
+ refundTo: "user.near",
312
+ },
313
+ {
314
+ intentsQuotationAdapter,
315
+ dexRouters: [v1Router, v2Router], // Compare multiple routers
316
+ bluechipTokens,
317
+ configAdapter,
318
+ currentUserAddress: "user.near",
319
+ }
320
+ );
321
+
322
+ console.log("Deposit address:", completeQuoteResult.intents.depositAddress);
323
+ console.log("Final amount out:", completeQuoteResult.finalAmountOut);
324
+
325
+ if (completeQuoteResult.preSwap) {
326
+ console.log("Pre-swap required:", completeQuoteResult.preSwap.quote);
327
+ console.log("Pre-swap executor:", completeQuoteResult.preSwap.executor);
328
+ // Execute pre-swap if needed
329
+ const preSwapResult = await completeQuoteResult.preSwap.executor.executeSwap({
330
+ quote: completeQuoteResult.preSwap.quote,
331
+ recipient: completeQuoteResult.intents.depositAddress,
332
+ // For V2 Router, also provide sender and receiveUser
333
+ ...(completeQuoteResult.preSwap.executor.getCapabilities().requiresRecipient && {
334
+ sender: "user.near",
335
+ receiveUser: completeQuoteResult.intents.depositAddress,
336
+ }),
337
+ });
338
+ }
339
+ ```
340
+
341
+ ## API Documentation
342
+
343
+ ### NearSmartRouter (V1)
344
+
345
+ Simple router implementation using FindPath API and REF Finance.
346
+
347
+ #### `quote(params: QuoteParams): Promise<QuoteResult>`
348
+
349
+ Get quote method that returns optimal swap path and output amount.
350
+
351
+ **Parameters:**
352
+ - `tokenIn`: Input token information
353
+ - `tokenOut`: Output token information
354
+ - `amountIn`: Input amount (string format, considering decimals)
355
+ - `slippage`: Slippage tolerance (prefer bps, 50 = 0.5%). Percent/decimal inputs are also accepted.
356
+ - `swapType`: Swap type ("EXACT_INPUT" | "EXACT_OUTPUT") - currently reserved for future use
357
+
358
+ **Returns:**
359
+ - `success`: Whether successful
360
+ - `amountOut`: Output amount
361
+ - `minAmountOut`: Minimum output amount (considering slippage)
362
+ - `routes`: Route information with pool details
363
+ - `rawRoutes`: Raw route data from server (for internal use)
364
+ - `error`: Error message (if failed)
365
+
366
+ #### `executeSwap(params: ExecuteParams): Promise<ExecuteResult>`
367
+
368
+ Execute swap method. Automatically handles token storage registration if needed.
369
+
370
+ **Parameters:**
371
+ - `quote`: Quote result from `quote()` method
372
+ - `recipient`: Recipient address
373
+ - `depositAddress`: Deposit address (optional, for cross-chain scenarios)
374
+
375
+ **Returns:**
376
+ - `success`: Whether successful
377
+ - `txHash`: Transaction hash
378
+ - `txHashArray`: Transaction hash array (if multiple transactions)
379
+ - `error`: Error message (if failed)
380
+
381
+ #### `getCapabilities(): RouterCapabilities`
382
+
383
+ Returns router capabilities:
384
+ - `requiresRecipient`: false
385
+ - `requiresFinalizeQuote`: false
386
+ - `requiresComplexRegistration`: false
387
+ - `supportedChain`: "near"
388
+
389
+ #### `getSupportedChain(): "near"`
390
+
391
+ Returns the supported chain identifier.
392
+
393
+ ### AggregateDexRouter (V2)
394
+
395
+ Advanced router implementation using Aggregate DEX contract with multi-DEX support.
396
+
397
+ #### `quote(params: RecipientQuoteParams): Promise<QuoteResult>`
398
+
399
+ Get quote method that requires sender and recipient parameters.
400
+
401
+ **Parameters:**
402
+ - `tokenIn`: Input token information
403
+ - `tokenOut`: Output token information
404
+ - `amountIn`: Input amount (string format, considering decimals)
405
+ - `slippage`: Slippage tolerance (prefer bps, 50 = 0.5%)
406
+ - `swapType`: Swap type ("EXACT_INPUT" | "EXACT_OUTPUT")
407
+ - `sender`: Sender address (required)
408
+ - `recipient`: Recipient address (required, can be same as sender)
409
+
410
+ **Returns:**
411
+ - `success`: Whether successful
412
+ - `amountOut`: Output amount
413
+ - `minAmountOut`: Minimum output amount (considering slippage)
414
+ - `routerMsg`: Router message for execution (required for executeSwap)
415
+ - `signature`: Signature for router message (required for executeSwap)
416
+ - `tokens`: Array of token addresses involved in the swap
417
+ - `dexs`: Array of DEX identifiers involved in the swap
418
+ - `error`: Error message (if failed)
419
+
420
+ #### `executeSwap(params: RecipientExecuteParams): Promise<ExecuteResult>`
421
+
422
+ Execute swap method. Automatically:
423
+ - Fetches fresh quote using `receiveUser` (depositAddress)
424
+ - Handles NEAR to wNEAR conversion if needed
425
+ - Registers user, receiveUser, and contract in all required tokens
426
+ - Executes swap via Aggregate DEX contract
427
+
428
+ **Parameters:**
429
+ - `quote`: Quote result from `quote()` method (used for initial validation)
430
+ - `sender`: Sender address (required)
431
+ - `receiveUser`: Recipient address, usually depositAddress (required)
432
+ - `recipient`: Optional, kept for compatibility
433
+
434
+ **Returns:**
435
+ - `success`: Whether successful
436
+ - `txHash`: Transaction hash
437
+ - `txHashArray`: Transaction hash array (if multiple transactions)
438
+ - `error`: Error message (if failed)
439
+
440
+ > **Important**: V2 Router automatically fetches a fresh quote during `executeSwap` using `receiveUser` to ensure the `routerMsg` and `signature` are correct for the final recipient address. You don't need to manually call `finalizeQuote`.
441
+
442
+ #### `finalizeQuote(params: QuoteParams, depositAddress: string): Promise<QuoteResult>`
443
+
444
+ > **Deprecated**: This method is kept for interface compatibility but is no longer needed. `executeSwap` automatically fetches the final quote using `receiveUser` (depositAddress).
445
+
446
+ #### `getCapabilities(): RouterCapabilities`
447
+
448
+ Returns router capabilities:
449
+ - `requiresRecipient`: true
450
+ - `requiresFinalizeQuote`: false (automatic during executeSwap)
451
+ - `requiresComplexRegistration`: true
452
+ - `supportedChain`: "near"
453
+
454
+ #### `getSupportedChain(): "near"`
455
+
456
+ Returns the supported chain identifier.
457
+
458
+ ### completeQuote
459
+
460
+ Complete quote function that integrates DEX Aggregator and NearIntents.
461
+
462
+ **Parameters:**
463
+ - `sourceToken`: Source token information
464
+ - `targetToken`: Target token information
465
+ - `sourceChain`: Source chain identifier ("near")
466
+ - `targetChain`: Target chain identifier (e.g., "bsc", "ethereum")
467
+ - `amountIn`: Input amount (string format)
468
+ - `slippage`: Slippage tolerance (prefer bps, 50 = 0.5%)
469
+ - `recipient`: Recipient address on target chain
470
+ - `refundTo`: Refund address (optional, defaults to recipient)
471
+
472
+ **Configuration:**
473
+ - `intentsQuotationAdapter`: NearIntents quotation adapter
474
+ - `dexRouter`: Single DEX Router instance (optional, use `dexRouters` for multiple)
475
+ - `dexRouters`: Array of DEX Router instances (optional, use `dexRouter` for single)
476
+ - `bluechipTokens`: Bluechip tokens configuration (USDT, USDC, NEAR)
477
+ - `configAdapter`: Configuration adapter
478
+ - `currentUserAddress`: Current user address (required for V2 Router)
479
+
480
+ **Returns:**
481
+ - `intents`: NearIntents quote result with depositAddress
482
+ - `preSwap`: Pre-swap information (if source token is not bluechip)
483
+ - `quote`: Pre-swap quote result
484
+ - `tokenIn`: Source token
485
+ - `tokenOut`: Bluechip token
486
+ - `executor`: Router instance to execute pre-swap
487
+ - `finalAmountOut`: Final output amount after NearIntents bridge
488
+
489
+ ## Router Comparison
490
+
491
+ | Feature | NearSmartRouter (V1) | AggregateDexRouter (V2) |
492
+ |---------|---------------------|-------------------------|
493
+ | API | FindPath | swapMultiDexPath |
494
+ | Execution | REF Finance | Aggregate DEX Contract |
495
+ | Recipient Required | No | Yes (sender + recipient) |
496
+ | Auto Registration | Basic (recipient only) | Advanced (user, receiveUser, contract) |
497
+ | Multi-DEX Support | Via FindPath | Native multi-DEX aggregation |
498
+ | NEAR → wNEAR | Manual | Automatic |
499
+ | Use Case | Simple swaps | Complex swaps, cross-chain |
500
+
501
+ ## Utility Functions
502
+
503
+ ### `normalizeTokenId(tokenId: string, wrapNearContractId?: string): string`
504
+
505
+ Normalize token ID by removing `nep141:` prefix and converting `near` to `wrap.near`.
506
+
507
+ ```typescript
508
+ import { normalizeTokenId } from "@rhea-finance/cross-chain-aggregation-dex";
509
+
510
+ normalizeTokenId("nep141:usdt.tether-token.near"); // "usdt.tether-token.near"
511
+ normalizeTokenId("near"); // "wrap.near"
512
+ normalizeTokenId("near", "custom-wrap.near"); // "custom-wrap.near"
513
+ ```
514
+
515
+ ### `convertSlippageToBasisPoints(slippage: number): number`
516
+
517
+ Convert slippage format to basis points (1 basis point = 0.01%).
518
+
519
+ ```typescript
520
+ import { convertSlippageToBasisPoints } from "@rhea-finance/cross-chain-aggregation-dex";
521
+
522
+ convertSlippageToBasisPoints(50); // 50 (already in bps)
523
+ convertSlippageToBasisPoints(0.5); // 50 (percent format)
524
+ convertSlippageToBasisPoints(0.005); // 50 (decimal format)
525
+ ```
526
+
527
+ ### `findBestBluechipToken(bluechipTokens: BluechipTokensConfig, wrapNearContractId?: string): TokenInfo`
528
+
529
+ Find the best bluechip token to use as intermediate token (priority order: USDT > USDC > wNEAR).
530
+
531
+ ```typescript
532
+ import { findBestBluechipToken } from "@rhea-finance/cross-chain-aggregation-dex";
533
+
534
+ const bluechipTokens = {
535
+ USDT: { address: "usdt.tether-token.near", symbol: "USDT", decimals: 6 },
536
+ USDC: { address: "usdc.near", symbol: "USDC", decimals: 6 },
537
+ NEAR: { address: "wrap.near", symbol: "wNEAR", decimals: 24 },
538
+ };
539
+
540
+ const bestToken = findBestBluechipToken(bluechipTokens);
541
+ // Returns USDT if available, otherwise USDC, otherwise wNEAR
542
+ ```
543
+
544
+ ### `isNearIntentsSupportedToken(token: TokenInfo, bluechipTokens?: BluechipTokensConfig): boolean`
545
+
546
+ Check if a token is supported by NearIntents (matches bluechip token configuration).
547
+
548
+ ```typescript
549
+ import { isNearIntentsSupportedToken } from "@rhea-finance/cross-chain-aggregation-dex";
550
+
551
+ const isSupported = isNearIntentsSupportedToken(tokenIn, bluechipTokens);
552
+ ```
553
+
554
+ ### `formatGasToTgas(gasInYoctoNEAR: string | number): string`
555
+
556
+ Format gas value from yoctoNEAR to Tgas string, avoiding scientific notation.
557
+
558
+ ```typescript
559
+ import { formatGasToTgas } from "@rhea-finance/cross-chain-aggregation-dex";
560
+
561
+ formatGasToTgas("300000000000000"); // "300"
562
+ ```
563
+
564
+ ### `formatGasString(gas: string | number | bigint): string`
565
+
566
+ Ensure gas value is a string without scientific notation.
567
+
568
+ ```typescript
569
+ import { formatGasString } from "@rhea-finance/cross-chain-aggregation-dex";
570
+
571
+ formatGasString(300000000000000); // "300000000000000"
572
+ formatGasString("3e14"); // "300000000000000"
573
+ ```
574
+
575
+ ## Logging
576
+
577
+ The SDK uses a simple logger with log level control. You can control logging via the `LOG_LEVEL` environment variable:
578
+
579
+ - `LOG_LEVEL=debug` - Show all logs (default in development)
580
+ - `LOG_LEVEL=info` - Show info, warn, and error logs
581
+ - `LOG_LEVEL=warn` - Show only warnings and errors (default in production)
582
+ - `LOG_LEVEL=error` - Show only errors
583
+ - `LOG_LEVEL=silent` - Disable all logs
584
+
585
+ ```typescript
586
+ import { logger } from "@rhea-finance/cross-chain-aggregation-dex";
587
+
588
+ // The logger is automatically used internally
589
+ // You can also use it in your code if needed
590
+ logger.debug("Debug message");
591
+ logger.info("Info message");
592
+ logger.warn("Warning message");
593
+ logger.error("Error message");
594
+ ```
595
+
596
+ ## Type Definitions
597
+
598
+ All type definitions can be imported from the package:
599
+
600
+ ```typescript
601
+ import type {
602
+ TokenInfo,
603
+ QuoteParams,
604
+ RecipientQuoteParams,
605
+ QuoteResult,
606
+ ExecuteParams,
607
+ RecipientExecuteParams,
608
+ ExecuteResult,
609
+ DexRouter,
610
+ RouterCapabilities,
611
+ BluechipTokensConfig,
612
+ BluechipTokenConfig,
613
+ Route,
614
+ PoolInfo,
615
+ } from "@rhea-finance/cross-chain-aggregation-dex";
616
+ ```
617
+
618
+ ### Key Types
619
+
620
+ - `TokenInfo`: Token information with address, symbol, decimals, and chain
621
+ - `QuoteParams`: Union type supporting both simple and recipient modes
622
+ - `QuoteResult`: Quote result with routes, amounts, and optional router-specific fields
623
+ - `ExecuteParams`: Union type supporting both simple and recipient execution modes
624
+ - `RouterCapabilities`: Router feature flags
625
+ - `BluechipTokensConfig`: Configuration for bluechip tokens (USDT, USDC, NEAR)
626
+
627
+ ## Development
628
+
629
+ ```bash
630
+ # Install dependencies
631
+ pnpm install
632
+
633
+ # Build
634
+ pnpm build
635
+
636
+ # Type check
637
+ pnpm type-check
638
+
639
+ # Lint
640
+ pnpm lint
641
+
642
+ # Development mode (watch file changes)
643
+ pnpm dev
644
+ ```
645
+
646
+ ## License
647
+
648
+ MIT
649
+
650
+ ## Related Links
651
+
652
+ - [GitHub Repository](https://github.com/rhea-finance/crossChain-aggregation-sdk)
653
+ - [Rhea Finance](https://rhea.finance)