@rhea-finance/cross-chain-aggregation-dex 0.1.5 → 0.1.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.
- package/README.md +313 -26
- package/dist/index.d.mts +174 -10
- package/dist/index.d.ts +174 -10
- package/dist/index.js +822 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +819 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
# @rhea-finance/cross-chain-aggregation-dex
|
|
2
2
|
|
|
3
|
-
A powerful TypeScript SDK for cross-chain DEX aggregation and routing on NEAR
|
|
3
|
+
A powerful TypeScript SDK for cross-chain DEX aggregation and routing on NEAR and EVM blockchains. 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
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
This SDK offers
|
|
7
|
+
This SDK offers three router implementations for different use cases:
|
|
8
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.
|
|
9
|
+
- **NearSmartRouter (V1)**: Simple routing via FindPath API and REF Finance execution. Best for straightforward swaps on NEAR without complex recipient handling.
|
|
10
|
+
- **AggregateDexRouter (V2)**: Advanced multi-DEX aggregation with automatic registration handling on NEAR. Supports complex scenarios with multiple recipients and automatic token registration.
|
|
11
|
+
- **BitgetRouter (EVM)**: EVM chain router implementation using Bitget DEX aggregator. Supports Ethereum, BSC, Polygon, Base, and other EVM-compatible chains with automatic balance checking, token approval, and gas optimization.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
All routers support optimal path finding, slippage protection, and can be combined with NearIntents for cross-chain functionality.
|
|
13
14
|
|
|
14
15
|
## Features
|
|
15
16
|
|
|
16
|
-
- 🔄 **DEX Aggregation Routing**: Automatically finds optimal swap paths across multiple DEXs on NEAR
|
|
17
|
-
- 🚀 **
|
|
17
|
+
- 🔄 **DEX Aggregation Routing**: Automatically finds optimal swap paths across multiple DEXs on NEAR and EVM chains
|
|
18
|
+
- 🚀 **Multi-Router Support**: Three router implementations (V1 Simple Router, V2 Aggregate Router, and EVM Router) for different use cases
|
|
19
|
+
- ⛓️ **Multi-Chain Support**: Native support for NEAR blockchain and EVM-compatible chains (Ethereum, BSC, Polygon, Base, etc.)
|
|
18
20
|
- 🌉 **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
|
+
- 🔀 **Pre-swap Handling**: Automatically converts non-bluechip tokens to bluechip tokens (USDT/USDC/wNEAR/ETH) when needed
|
|
22
|
+
- 🔐 **Auto Registration**: Automatically handles token storage registration for users and contracts (NEAR)
|
|
23
|
+
- 💰 **Auto Approval**: Automatically handles ERC20 token approval with retry mechanism (EVM)
|
|
24
|
+
- ⛽ **Gas Optimization**: Intelligent gas estimation with EIP-1559 support and fallback mechanisms (EVM)
|
|
21
25
|
- 📊 **Multi-Router Comparison**: Compare quotes from multiple routers and select the best one
|
|
22
26
|
- 📦 **Type Safety**: Complete TypeScript type definitions with full IntelliSense support
|
|
23
27
|
- 🔌 **Adapter Pattern**: Flexible adapter interfaces for easy integration with any backend or wallet
|
|
@@ -46,6 +50,8 @@ import {
|
|
|
46
50
|
SwapMultiDexPathAdapter,
|
|
47
51
|
IntentsQuotationAdapter,
|
|
48
52
|
NearChainAdapter,
|
|
53
|
+
EvmChainAdapter,
|
|
54
|
+
BitgetAdapter,
|
|
49
55
|
ConfigAdapter,
|
|
50
56
|
} from "@rhea-finance/cross-chain-aggregation-dex";
|
|
51
57
|
|
|
@@ -109,6 +115,65 @@ const nearChainAdapter: NearChainAdapter = {
|
|
|
109
115
|
},
|
|
110
116
|
};
|
|
111
117
|
|
|
118
|
+
// Bitget DEX aggregator adapter (for BitgetRouter EVM)
|
|
119
|
+
const bitgetAdapter: BitgetAdapter = {
|
|
120
|
+
async quote(params) {
|
|
121
|
+
const response = await fetch("https://api.bitget.com/v1/mix/market/swap-best-book", {
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers: { "Content-Type": "application/json" },
|
|
124
|
+
body: JSON.stringify({
|
|
125
|
+
chainId: params.chainId,
|
|
126
|
+
tokenIn: params.tokenIn,
|
|
127
|
+
tokenOut: params.tokenOut,
|
|
128
|
+
amountIn: params.amountIn,
|
|
129
|
+
slippage: params.slippage,
|
|
130
|
+
userAddress: params.userAddress,
|
|
131
|
+
}),
|
|
132
|
+
});
|
|
133
|
+
return response.json();
|
|
134
|
+
},
|
|
135
|
+
async swap(params) {
|
|
136
|
+
const response = await fetch("https://api.bitget.com/v1/mix/market/swap", {
|
|
137
|
+
method: "POST",
|
|
138
|
+
headers: { "Content-Type": "application/json" },
|
|
139
|
+
body: JSON.stringify({
|
|
140
|
+
chainId: params.chainId,
|
|
141
|
+
tokenIn: params.tokenIn,
|
|
142
|
+
tokenOut: params.tokenOut,
|
|
143
|
+
amountIn: params.amountIn,
|
|
144
|
+
slippage: params.slippage,
|
|
145
|
+
userAddress: params.userAddress,
|
|
146
|
+
market: params.market,
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
return response.json();
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// EVM chain interaction adapter (for BitgetRouter)
|
|
154
|
+
const evmChainAdapter: EvmChainAdapter = {
|
|
155
|
+
async sendTransaction(params) {
|
|
156
|
+
// Use your EVM wallet or provider to send transaction
|
|
157
|
+
// Return { status: "success", txHash: "..." } or { status: "failed", message: "..." }
|
|
158
|
+
},
|
|
159
|
+
async getBalance(params) {
|
|
160
|
+
// Optional: Get token balance (for ERC20) or native balance (if tokenAddress is undefined)
|
|
161
|
+
// Return balance as string
|
|
162
|
+
},
|
|
163
|
+
async getAllowance(params) {
|
|
164
|
+
// Optional: Get ERC20 token allowance
|
|
165
|
+
// Return allowance as string
|
|
166
|
+
},
|
|
167
|
+
async approve(params) {
|
|
168
|
+
// Optional: Approve ERC20 token spending
|
|
169
|
+
// Return { status: "success", txHash: "..." } or { status: "failed", message: "..." }
|
|
170
|
+
},
|
|
171
|
+
async getSigner() {
|
|
172
|
+
// Optional: Get ethers signer for gas estimation
|
|
173
|
+
// Return ethers.Signer instance
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
|
|
112
177
|
// Configuration adapter
|
|
113
178
|
const configAdapter: ConfigAdapter = {
|
|
114
179
|
getRefExchangeId: () => "v2.ref-finance.near",
|
|
@@ -116,6 +181,7 @@ const configAdapter: ConfigAdapter = {
|
|
|
116
181
|
getFindPathUrl: () => "https://smartrouter.ref.finance",
|
|
117
182
|
getTokenStorageDepositRead: () => "1250000000000000000000",
|
|
118
183
|
getAggregateDexContractId: () => "aggregate-dex-contract.near", // For V2 Router
|
|
184
|
+
getEvmNativeWrappedTokenAddress: () => "0x4200000000000000000000000000000000000006", // Optional: WETH address for EVM chains
|
|
119
185
|
};
|
|
120
186
|
```
|
|
121
187
|
|
|
@@ -145,6 +211,18 @@ const v2Router = new AggregateDexRouter({
|
|
|
145
211
|
});
|
|
146
212
|
```
|
|
147
213
|
|
|
214
|
+
#### Using BitgetRouter (EVM)
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import { BitgetRouter } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
218
|
+
|
|
219
|
+
const evmRouter = new BitgetRouter({
|
|
220
|
+
bitgetAdapter,
|
|
221
|
+
evmChainAdapter,
|
|
222
|
+
chainId: 1, // Ethereum mainnet (1), BSC (56), Polygon (137), Base (8453), etc.
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
148
226
|
### 3. Get Quote
|
|
149
227
|
|
|
150
228
|
#### Using NearSmartRouter (V1)
|
|
@@ -152,6 +230,7 @@ const v2Router = new AggregateDexRouter({
|
|
|
152
230
|
```typescript
|
|
153
231
|
import { TokenInfo } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
154
232
|
|
|
233
|
+
// NEAR tokens
|
|
155
234
|
const tokenIn: TokenInfo = {
|
|
156
235
|
address: "token-a.near",
|
|
157
236
|
symbol: "TOKENA",
|
|
@@ -166,6 +245,21 @@ const tokenOut: TokenInfo = {
|
|
|
166
245
|
chain: "near",
|
|
167
246
|
};
|
|
168
247
|
|
|
248
|
+
// EVM tokens (for BitgetRouter)
|
|
249
|
+
const evmTokenIn: TokenInfo = {
|
|
250
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
|
|
251
|
+
symbol: "USDC",
|
|
252
|
+
decimals: 6,
|
|
253
|
+
chain: "evm",
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const evmTokenOut: TokenInfo = {
|
|
257
|
+
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT on Ethereum
|
|
258
|
+
symbol: "USDT",
|
|
259
|
+
decimals: 6,
|
|
260
|
+
chain: "evm",
|
|
261
|
+
};
|
|
262
|
+
|
|
169
263
|
// V1 Router - Simple quote (no recipient required)
|
|
170
264
|
const quote = await v1Router.quote({
|
|
171
265
|
tokenIn,
|
|
@@ -209,6 +303,29 @@ if (quote.success) {
|
|
|
209
303
|
}
|
|
210
304
|
```
|
|
211
305
|
|
|
306
|
+
#### Using BitgetRouter (EVM)
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
// EVM Router - Requires sender and recipient
|
|
310
|
+
const quote = await evmRouter.quote({
|
|
311
|
+
tokenIn: evmTokenIn,
|
|
312
|
+
tokenOut: evmTokenOut,
|
|
313
|
+
amountIn: "1000000", // 1 USDC (6 decimals)
|
|
314
|
+
slippage: 50, // 0.5% (50 basis points)
|
|
315
|
+
swapType: "EXACT_INPUT",
|
|
316
|
+
sender: "0x...", // Required for EVM Router
|
|
317
|
+
recipient: "0x...", // Required for EVM Router (can be same as sender)
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
if (quote.success) {
|
|
321
|
+
console.log("Amount out:", quote.amountOut);
|
|
322
|
+
console.log("Min amount out:", quote.minAmountOut);
|
|
323
|
+
console.log("Router message:", quote.routerMsg);
|
|
324
|
+
} else {
|
|
325
|
+
console.error("Quote failed:", quote.error);
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
212
329
|
### 4. Execute Swap
|
|
213
330
|
|
|
214
331
|
#### Using NearSmartRouter (V1)
|
|
@@ -249,6 +366,27 @@ if (result.success) {
|
|
|
249
366
|
|
|
250
367
|
> **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
368
|
|
|
369
|
+
#### Using BitgetRouter (EVM)
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
// EVM Router - Requires sender and receiveUser
|
|
373
|
+
const result = await evmRouter.executeSwap({
|
|
374
|
+
quote,
|
|
375
|
+
sender: "0x...", // Required for EVM Router
|
|
376
|
+
receiveUser: "0x...", // Required for EVM Router (usually depositAddress)
|
|
377
|
+
recipient: "0x...", // Optional, kept for compatibility
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
if (result.success) {
|
|
381
|
+
console.log("Transaction hash:", result.txHash);
|
|
382
|
+
console.log("Transaction hashes:", result.txHashArray);
|
|
383
|
+
} else {
|
|
384
|
+
console.error("Swap failed:", result.error);
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
> **Note**: EVM Router automatically checks token balance and approval before executing. If approval is insufficient, it will automatically approve the token with retry mechanism.
|
|
389
|
+
|
|
252
390
|
### 5. Complete Quote (DEX Aggregator + NearIntents)
|
|
253
391
|
|
|
254
392
|
The `completeQuote` function integrates DEX aggregation with NearIntents bridge for cross-chain swaps. It automatically handles pre-swaps when needed:
|
|
@@ -256,6 +394,7 @@ The `completeQuote` function integrates DEX aggregation with NearIntents bridge
|
|
|
256
394
|
```typescript
|
|
257
395
|
import { completeQuote } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
258
396
|
|
|
397
|
+
// For NEAR chains
|
|
259
398
|
const bluechipTokens = {
|
|
260
399
|
USDT: {
|
|
261
400
|
address: "usdt.tether-token.near",
|
|
@@ -277,7 +416,29 @@ const bluechipTokens = {
|
|
|
277
416
|
},
|
|
278
417
|
};
|
|
279
418
|
|
|
280
|
-
//
|
|
419
|
+
// For EVM chains
|
|
420
|
+
const evmBluechipTokens = {
|
|
421
|
+
USDT: {
|
|
422
|
+
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT on Ethereum
|
|
423
|
+
symbol: "USDT",
|
|
424
|
+
decimals: 6,
|
|
425
|
+
assetId: "evm:0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
426
|
+
},
|
|
427
|
+
USDC: {
|
|
428
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
|
|
429
|
+
symbol: "USDC",
|
|
430
|
+
decimals: 6,
|
|
431
|
+
assetId: "evm:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
432
|
+
},
|
|
433
|
+
ETH: {
|
|
434
|
+
address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH on Ethereum
|
|
435
|
+
symbol: "WETH",
|
|
436
|
+
decimals: 18,
|
|
437
|
+
assetId: "evm:0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
438
|
+
},
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
// Using single router (NEAR chain)
|
|
281
442
|
const completeQuoteResult = await completeQuote(
|
|
282
443
|
{
|
|
283
444
|
sourceToken: tokenIn,
|
|
@@ -298,6 +459,28 @@ const completeQuoteResult = await completeQuote(
|
|
|
298
459
|
}
|
|
299
460
|
);
|
|
300
461
|
|
|
462
|
+
// Using EVM router
|
|
463
|
+
const evmCompleteQuoteResult = await completeQuote(
|
|
464
|
+
{
|
|
465
|
+
sourceToken: evmTokenIn,
|
|
466
|
+
targetToken: tokenOut, // Target token on destination chain
|
|
467
|
+
sourceChain: "ethereum", // or "evm", "bsc", "polygon", "base", etc.
|
|
468
|
+
targetChain: "near",
|
|
469
|
+
amountIn: "1000000", // 1 USDC (6 decimals)
|
|
470
|
+
slippage: 50,
|
|
471
|
+
recipient: "user.near", // Target chain address
|
|
472
|
+
refundTo: "0x...", // EVM address
|
|
473
|
+
evmChainId: 1, // Optional: explicitly specify EVM chain ID (1 for Ethereum)
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
intentsQuotationAdapter,
|
|
477
|
+
dexRouter: evmRouter,
|
|
478
|
+
bluechipTokens: evmBluechipTokens, // Use EVM bluechip tokens
|
|
479
|
+
configAdapter,
|
|
480
|
+
currentUserAddress: "0x...", // Required for EVM Router
|
|
481
|
+
}
|
|
482
|
+
);
|
|
483
|
+
|
|
301
484
|
// Using multiple routers (compares and selects best quote)
|
|
302
485
|
const completeQuoteResult = await completeQuote(
|
|
303
486
|
{
|
|
@@ -455,6 +638,66 @@ Returns router capabilities:
|
|
|
455
638
|
|
|
456
639
|
Returns the supported chain identifier.
|
|
457
640
|
|
|
641
|
+
### BitgetRouter (EVM)
|
|
642
|
+
|
|
643
|
+
EVM chain router implementation using Bitget DEX aggregator. Supports automatic balance checking, token approval, and gas optimization.
|
|
644
|
+
|
|
645
|
+
#### `quote(params: RecipientQuoteParams): Promise<QuoteResult>`
|
|
646
|
+
|
|
647
|
+
Get quote method that requires sender and recipient parameters.
|
|
648
|
+
|
|
649
|
+
**Parameters:**
|
|
650
|
+
- `tokenIn`: Input token information (EVM address)
|
|
651
|
+
- `tokenOut`: Output token information (EVM address)
|
|
652
|
+
- `amountIn`: Input amount (string format, considering decimals)
|
|
653
|
+
- `slippage`: Slippage tolerance (prefer bps, 50 = 0.5%)
|
|
654
|
+
- `swapType`: Swap type ("EXACT_INPUT" | "EXACT_OUTPUT")
|
|
655
|
+
- `sender`: Sender address (required, EVM address)
|
|
656
|
+
- `recipient`: Recipient address (required, EVM address, can be same as sender)
|
|
657
|
+
|
|
658
|
+
**Returns:**
|
|
659
|
+
- `success`: Whether successful
|
|
660
|
+
- `amountOut`: Output amount
|
|
661
|
+
- `minAmountOut`: Minimum output amount (considering slippage)
|
|
662
|
+
- `routerMsg`: Router message for execution (required for executeSwap)
|
|
663
|
+
- `error`: Error message (if failed)
|
|
664
|
+
|
|
665
|
+
#### `executeSwap(params: RecipientExecuteParams): Promise<ExecuteResult>`
|
|
666
|
+
|
|
667
|
+
Execute swap method. Automatically:
|
|
668
|
+
- Checks token balance (for ERC20) or native balance (for native tokens)
|
|
669
|
+
- Checks and approves ERC20 token if needed (with retry mechanism)
|
|
670
|
+
- Estimates gas with buffer and EIP-1559 support
|
|
671
|
+
- Executes swap via Bitget aggregator
|
|
672
|
+
|
|
673
|
+
**Parameters:**
|
|
674
|
+
- `quote`: Quote result from `quote()` method
|
|
675
|
+
- `sender`: Sender address (required, EVM address)
|
|
676
|
+
- `receiveUser`: Recipient address, usually depositAddress (required, EVM address)
|
|
677
|
+
- `recipient`: Optional, kept for compatibility
|
|
678
|
+
|
|
679
|
+
**Returns:**
|
|
680
|
+
- `success`: Whether successful
|
|
681
|
+
- `txHash`: Transaction hash
|
|
682
|
+
- `txHashArray`: Transaction hash array (if multiple transactions)
|
|
683
|
+
- `error`: Error message (if failed)
|
|
684
|
+
|
|
685
|
+
#### `getCapabilities(): RouterCapabilities`
|
|
686
|
+
|
|
687
|
+
Returns router capabilities:
|
|
688
|
+
- `requiresRecipient`: true
|
|
689
|
+
- `requiresFinalizeQuote`: false
|
|
690
|
+
- `requiresComplexRegistration`: false
|
|
691
|
+
- `supportedChain`: "evm"
|
|
692
|
+
|
|
693
|
+
#### `getSupportedChain(): "evm"`
|
|
694
|
+
|
|
695
|
+
Returns the supported chain identifier.
|
|
696
|
+
|
|
697
|
+
#### `getChainId(): number`
|
|
698
|
+
|
|
699
|
+
Returns the EVM chain ID (e.g., 1 for Ethereum, 56 for BSC, 137 for Polygon, 8453 for Base).
|
|
700
|
+
|
|
458
701
|
### completeQuote
|
|
459
702
|
|
|
460
703
|
Complete quote function that integrates DEX Aggregator and NearIntents.
|
|
@@ -462,20 +705,21 @@ Complete quote function that integrates DEX Aggregator and NearIntents.
|
|
|
462
705
|
**Parameters:**
|
|
463
706
|
- `sourceToken`: Source token information
|
|
464
707
|
- `targetToken`: Target token information
|
|
465
|
-
- `sourceChain`: Source chain identifier ("near")
|
|
466
|
-
- `targetChain`: Target chain identifier (e.g., "bsc", "ethereum")
|
|
708
|
+
- `sourceChain`: Source chain identifier ("near", "evm", "ethereum", "bsc", "polygon", "base", etc.)
|
|
709
|
+
- `targetChain`: Target chain identifier (e.g., "bsc", "ethereum", "near")
|
|
467
710
|
- `amountIn`: Input amount (string format)
|
|
468
711
|
- `slippage`: Slippage tolerance (prefer bps, 50 = 0.5%)
|
|
469
712
|
- `recipient`: Recipient address on target chain
|
|
470
713
|
- `refundTo`: Refund address (optional, defaults to recipient)
|
|
714
|
+
- `evmChainId`: Optional EVM chain ID for precise chain identification (e.g., 1 for Ethereum, 56 for BSC)
|
|
471
715
|
|
|
472
716
|
**Configuration:**
|
|
473
717
|
- `intentsQuotationAdapter`: NearIntents quotation adapter
|
|
474
718
|
- `dexRouter`: Single DEX Router instance (optional, use `dexRouters` for multiple)
|
|
475
719
|
- `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)
|
|
720
|
+
- `bluechipTokens`: Bluechip tokens configuration (USDT, USDC, NEAR for NEAR chains; USDT, USDC, ETH for EVM chains)
|
|
721
|
+
- `configAdapter`: Configuration adapter (with optional `getEvmNativeWrappedTokenAddress` for EVM chains)
|
|
722
|
+
- `currentUserAddress`: Current user address (required for V2 Router and EVM Router)
|
|
479
723
|
|
|
480
724
|
**Returns:**
|
|
481
725
|
- `intents`: NearIntents quote result with depositAddress
|
|
@@ -488,15 +732,19 @@ Complete quote function that integrates DEX Aggregator and NearIntents.
|
|
|
488
732
|
|
|
489
733
|
## Router Comparison
|
|
490
734
|
|
|
491
|
-
| Feature | NearSmartRouter (V1) | AggregateDexRouter (V2) |
|
|
492
|
-
|
|
493
|
-
|
|
|
494
|
-
|
|
|
495
|
-
|
|
|
496
|
-
|
|
|
497
|
-
|
|
|
498
|
-
|
|
|
499
|
-
|
|
|
735
|
+
| Feature | NearSmartRouter (V1) | AggregateDexRouter (V2) | BitgetRouter (EVM) |
|
|
736
|
+
|---------|---------------------|-------------------------|-------------------|
|
|
737
|
+
| Chain | NEAR | NEAR | EVM (Ethereum, BSC, Polygon, Base, etc.) |
|
|
738
|
+
| API | FindPath | swapMultiDexPath | Bitget DEX Aggregator |
|
|
739
|
+
| Execution | REF Finance | Aggregate DEX Contract | Direct EVM Transaction |
|
|
740
|
+
| Recipient Required | No | Yes (sender + recipient) | Yes (sender + recipient) |
|
|
741
|
+
| Auto Registration | Basic (recipient only) | Advanced (user, receiveUser, contract) | N/A (EVM) |
|
|
742
|
+
| Auto Approval | N/A (NEAR) | N/A (NEAR) | Yes (ERC20 with retry) |
|
|
743
|
+
| Balance Check | No | No | Yes (automatic) |
|
|
744
|
+
| Gas Optimization | N/A (NEAR) | N/A (NEAR) | Yes (EIP-1559 support) |
|
|
745
|
+
| Multi-DEX Support | Via FindPath | Native multi-DEX aggregation | Via Bitget Aggregator |
|
|
746
|
+
| NEAR → wNEAR | Manual | Automatic | N/A (EVM) |
|
|
747
|
+
| Use Case | Simple swaps on NEAR | Complex swaps on NEAR, cross-chain | EVM chain swaps, cross-chain |
|
|
500
748
|
|
|
501
749
|
## Utility Functions
|
|
502
750
|
|
|
@@ -543,7 +791,7 @@ const bestToken = findBestBluechipToken(bluechipTokens);
|
|
|
543
791
|
|
|
544
792
|
### `isNearIntentsSupportedToken(token: TokenInfo, bluechipTokens?: BluechipTokensConfig): boolean`
|
|
545
793
|
|
|
546
|
-
Check if a token is supported by NearIntents (matches bluechip token configuration).
|
|
794
|
+
Check if a token is supported by NearIntents on NEAR chains (matches bluechip token configuration).
|
|
547
795
|
|
|
548
796
|
```typescript
|
|
549
797
|
import { isNearIntentsSupportedToken } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
@@ -551,6 +799,43 @@ import { isNearIntentsSupportedToken } from "@rhea-finance/cross-chain-aggregati
|
|
|
551
799
|
const isSupported = isNearIntentsSupportedToken(tokenIn, bluechipTokens);
|
|
552
800
|
```
|
|
553
801
|
|
|
802
|
+
### `normalizeEvmAddress(address: string): string`
|
|
803
|
+
|
|
804
|
+
Normalize EVM address to lowercase format for comparison.
|
|
805
|
+
|
|
806
|
+
```typescript
|
|
807
|
+
import { normalizeEvmAddress } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
808
|
+
|
|
809
|
+
normalizeEvmAddress("0xABC..."); // "0xabc..." (lowercase)
|
|
810
|
+
```
|
|
811
|
+
|
|
812
|
+
### `isEvmIntentsSupportedToken(token: TokenInfo, bluechipTokens?: BluechipTokensConfig): boolean`
|
|
813
|
+
|
|
814
|
+
Check if a token is supported by NearIntents on EVM chains (matches bluechip token configuration).
|
|
815
|
+
|
|
816
|
+
```typescript
|
|
817
|
+
import { isEvmIntentsSupportedToken } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
818
|
+
|
|
819
|
+
const isSupported = isEvmIntentsSupportedToken(evmTokenIn, evmBluechipTokens);
|
|
820
|
+
```
|
|
821
|
+
|
|
822
|
+
### `findBestEvmBluechipToken(bluechipTokens: BluechipTokensConfig, nativeTokenAddress?: string): TokenInfo`
|
|
823
|
+
|
|
824
|
+
Find the best bluechip token for EVM chains (priority order: USDT > USDC > ETH/WETH).
|
|
825
|
+
|
|
826
|
+
```typescript
|
|
827
|
+
import { findBestEvmBluechipToken } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
828
|
+
|
|
829
|
+
const evmBluechipTokens = {
|
|
830
|
+
USDT: { address: "0x...", symbol: "USDT", decimals: 6 },
|
|
831
|
+
USDC: { address: "0x...", symbol: "USDC", decimals: 6 },
|
|
832
|
+
ETH: { address: "0x...", symbol: "WETH", decimals: 18 },
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
const bestToken = findBestEvmBluechipToken(evmBluechipTokens, "0x..."); // Optional WETH address
|
|
836
|
+
// Returns USDT if available, otherwise USDC, otherwise ETH/WETH
|
|
837
|
+
```
|
|
838
|
+
|
|
554
839
|
### `formatGasToTgas(gasInYoctoNEAR: string | number): string`
|
|
555
840
|
|
|
556
841
|
Format gas value from yoctoNEAR to Tgas string, avoiding scientific notation.
|
|
@@ -622,7 +907,9 @@ import type {
|
|
|
622
907
|
- `QuoteResult`: Quote result with routes, amounts, and optional router-specific fields
|
|
623
908
|
- `ExecuteParams`: Union type supporting both simple and recipient execution modes
|
|
624
909
|
- `RouterCapabilities`: Router feature flags
|
|
625
|
-
- `BluechipTokensConfig`: Configuration for bluechip tokens (USDT, USDC, NEAR)
|
|
910
|
+
- `BluechipTokensConfig`: Configuration for bluechip tokens (USDT, USDC, NEAR for NEAR chains; USDT, USDC, ETH for EVM chains)
|
|
911
|
+
- `BitgetAdapter`: Adapter interface for Bitget DEX aggregator API
|
|
912
|
+
- `EvmChainAdapter`: Adapter interface for EVM chain interactions (sendTransaction, getBalance, approve, etc.)
|
|
626
913
|
|
|
627
914
|
## Development
|
|
628
915
|
|