@cowprotocol/sdk-bridging 0.3.3-beta.0 → 0.4.0
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 +265 -0
- package/dist/index.d.mts +158 -10
- package/dist/index.d.ts +158 -10
- package/dist/index.js +692 -181
- package/dist/index.mjs +692 -181
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -149,6 +149,271 @@ if (confirm(`You will get at least: ${buyAmount}, ok?`)) {
|
|
|
149
149
|
}
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
+
## Multi-Provider Quote Comparison
|
|
153
|
+
|
|
154
|
+
The `getMultiQuotes()` method allows you to get quotes from multiple bridge providers simultaneously, with support for progressive results as each provider responds.
|
|
155
|
+
|
|
156
|
+
### Basic Multi-Quote Usage
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { MultiQuoteRequest } from '@cowprotocol/sdk-bridging'
|
|
160
|
+
|
|
161
|
+
const multiQuoteRequest: MultiQuoteRequest = {
|
|
162
|
+
quoteBridgeRequest: parameters, // Same parameters as above
|
|
163
|
+
providerDappIds: ['provider1', 'provider2'], // Optional: specify which providers to query
|
|
164
|
+
advancedSettings: {
|
|
165
|
+
slippageBps: 100, // 1% slippage tolerance
|
|
166
|
+
},
|
|
167
|
+
options: {
|
|
168
|
+
totalTimeout: 15000, // 15 seconds total timeout
|
|
169
|
+
providerTimeout: 8000, // 8 seconds per provider timeout
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Get quotes from all providers
|
|
174
|
+
const results = await sdk.bridging.getMultiQuotes(multiQuoteRequest)
|
|
175
|
+
|
|
176
|
+
results.forEach((result) => {
|
|
177
|
+
if (result.quote) {
|
|
178
|
+
console.log(`Quote from ${result.providerDappId}:`, result.quote)
|
|
179
|
+
} else {
|
|
180
|
+
console.log(`Error from ${result.providerDappId}:`, result.error?.message)
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Progressive Quote Results
|
|
186
|
+
|
|
187
|
+
For better user experience, you can receive quotes progressively as each provider responds:
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
const progressiveResults: MultiQuoteResult[] = []
|
|
191
|
+
|
|
192
|
+
const multiQuoteRequest: MultiQuoteRequest = {
|
|
193
|
+
quoteBridgeRequest: parameters,
|
|
194
|
+
options: {
|
|
195
|
+
// Receive quotes as they arrive
|
|
196
|
+
onQuoteResult: (result) => {
|
|
197
|
+
progressiveResults.push(result)
|
|
198
|
+
|
|
199
|
+
if (result.quote) {
|
|
200
|
+
console.log(`✅ Quote received from ${result.providerDappId}`)
|
|
201
|
+
// Update UI immediately with the new quote
|
|
202
|
+
displayQuoteInUI(result)
|
|
203
|
+
} else {
|
|
204
|
+
console.log(`❌ Error from ${result.providerDappId}: ${result.error?.message}`)
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
totalTimeout: 20000, // 20 seconds total timeout
|
|
208
|
+
providerTimeout: 5000 // 5 seconds per provider timeout
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// This will return all results once completed (or timed out)
|
|
213
|
+
const finalResults = await sdk.bridging.getMultiQuotes(multiQuoteRequest)
|
|
214
|
+
|
|
215
|
+
console.log(`Received ${finalResults.filter(r => r.quote).length} successful quotes out of ${finalResults.length} providers`)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Advanced Multi-Quote Example
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
// Example with React state management
|
|
222
|
+
const [quotes, setQuotes] = useState<MultiQuoteResult[]>([])
|
|
223
|
+
const [isLoading, setIsLoading] = useState(false)
|
|
224
|
+
|
|
225
|
+
const fetchQuotes = async () => {
|
|
226
|
+
setIsLoading(true)
|
|
227
|
+
setQuotes([])
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
const results = await sdk.bridging.getMultiQuotes({
|
|
231
|
+
quoteBridgeRequest: parameters,
|
|
232
|
+
options: {
|
|
233
|
+
onQuoteResult: (result) => {
|
|
234
|
+
// Add quote to state as it arrives
|
|
235
|
+
setQuotes(prev => [...prev, result])
|
|
236
|
+
|
|
237
|
+
if (result.quote) {
|
|
238
|
+
// Optional: Auto-select best quote
|
|
239
|
+
if (isBestQuote(result)) {
|
|
240
|
+
selectQuote(result)
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
// Handle errors
|
|
244
|
+
console.error(`Provider ${result.providerDappId} failed:`, result.error?.message)
|
|
245
|
+
// Update UI to show provider is unavailable
|
|
246
|
+
setProviderStatus(prev => ({
|
|
247
|
+
...prev,
|
|
248
|
+
[result.providerDappId]: 'error'
|
|
249
|
+
}))
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
totalTimeout: 30000, // 30 seconds total timeout
|
|
253
|
+
providerTimeout: 10000 // 10 seconds per provider timeout
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
console.log('All quotes completed:', results)
|
|
258
|
+
} catch (error) {
|
|
259
|
+
console.error('Multi-quote failed:', error)
|
|
260
|
+
} finally {
|
|
261
|
+
setIsLoading(false)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Helper function to determine best quote
|
|
266
|
+
const isBestQuote = (result: MultiQuoteResult): boolean => {
|
|
267
|
+
if (!result.quote) return false
|
|
268
|
+
|
|
269
|
+
const currentBest = quotes.find(q => q.quote)
|
|
270
|
+
if (!currentBest?.quote) return true
|
|
271
|
+
|
|
272
|
+
// Compare buy amounts after slippage
|
|
273
|
+
return result.quote.bridge.amountsAndCosts.afterSlippage.buyAmount >
|
|
274
|
+
currentBest.quote.bridge.amountsAndCosts.afterSlippage.buyAmount
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Timeout Configuration
|
|
279
|
+
|
|
280
|
+
The `getMultiQuotes()` method supports two types of timeouts for fine-grained control:
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
const results = await sdk.bridging.getMultiQuotes({
|
|
284
|
+
quoteBridgeRequest: parameters,
|
|
285
|
+
options: {
|
|
286
|
+
// Global timeout: Maximum time to wait for all providers to complete
|
|
287
|
+
totalTimeout: 30000, // 30 seconds (default)
|
|
288
|
+
|
|
289
|
+
// Individual provider timeout: Maximum time each provider has to respond
|
|
290
|
+
providerTimeout: 15000, // 15 seconds (default)
|
|
291
|
+
|
|
292
|
+
onQuoteResult: (result) => {
|
|
293
|
+
// Handle progressive results
|
|
294
|
+
console.log(`Received result from ${result.providerDappId}`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**How timeouts work:**
|
|
301
|
+
- `providerTimeout`: Each provider has this amount of time to complete their quote request. If exceeded, that provider returns a timeout error.
|
|
302
|
+
- `totalTimeout`: The total time to wait for all providers. After this time, any remaining providers are marked as timed out.
|
|
303
|
+
- Providers that complete within their individual timeout but after the global timeout will still be included in the final results.
|
|
304
|
+
|
|
305
|
+
## Best Quote Selection
|
|
306
|
+
|
|
307
|
+
The `getBestQuote()` method provides an optimized way to get only the best quote from multiple providers, with progressive updates as better quotes are found. This is perfect for applications that only need the single best result.
|
|
308
|
+
|
|
309
|
+
### Basic Best Quote Usage
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
import { MultiQuoteRequest } from '@cowprotocol/sdk-bridging'
|
|
313
|
+
|
|
314
|
+
// Get the best quote from all available providers
|
|
315
|
+
const bestQuote = await sdk.bridging.getBestQuote({
|
|
316
|
+
quoteBridgeRequest: parameters, // Same parameters as above
|
|
317
|
+
providerDappIds: ['provider1', 'provider2'], // Optional: specify which providers to query
|
|
318
|
+
advancedSettings: {
|
|
319
|
+
slippageBps: 100, // 1% slippage tolerance
|
|
320
|
+
},
|
|
321
|
+
options: {
|
|
322
|
+
totalTimeout: 15000, // 15 seconds total timeout
|
|
323
|
+
providerTimeout: 8000, // 8 seconds per provider timeout
|
|
324
|
+
}
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
if (bestQuote?.quote) {
|
|
328
|
+
console.log(`Best quote from ${bestQuote.providerDappId}:`, bestQuote.quote)
|
|
329
|
+
const { buyAmount } = bestQuote.quote.bridge.amountsAndCosts.afterSlippage
|
|
330
|
+
console.log(`You will receive: ${buyAmount} tokens`)
|
|
331
|
+
} else if (bestQuote?.error) {
|
|
332
|
+
console.log('All providers failed, first error:', bestQuote.error.message)
|
|
333
|
+
} else {
|
|
334
|
+
console.log('No quotes available')
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Progressive Best Quote Updates
|
|
339
|
+
|
|
340
|
+
For real-time updates, you can receive notifications each time a better quote is found:
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
let currentBest: MultiQuoteResult | null = null
|
|
344
|
+
|
|
345
|
+
const bestQuote = await sdk.bridging.getBestQuote({
|
|
346
|
+
quoteBridgeRequest: parameters,
|
|
347
|
+
options: {
|
|
348
|
+
// Called whenever a better quote is found
|
|
349
|
+
onQuoteResult: (result) => {
|
|
350
|
+
currentBest = result
|
|
351
|
+
console.log(`🚀 New best quote from ${result.providerDappId}!`)
|
|
352
|
+
|
|
353
|
+
if (result.quote) {
|
|
354
|
+
const buyAmount = result.quote.bridge.amountsAndCosts.afterSlippage.buyAmount
|
|
355
|
+
console.log(`Better quote found: ${buyAmount} tokens`)
|
|
356
|
+
|
|
357
|
+
// Update UI immediately with the new best quote
|
|
358
|
+
updateBestQuoteInUI(result)
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
totalTimeout: 20000, // 20 seconds total timeout
|
|
362
|
+
providerTimeout: 5000 // 5 seconds per provider timeout
|
|
363
|
+
}
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
console.log('Final best quote:', bestQuote)
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### Error Handling with Best Quote
|
|
370
|
+
|
|
371
|
+
When all providers fail, `getBestQuote()` returns the first provider's error:
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
const bestQuote = await sdk.bridging.getBestQuote({
|
|
375
|
+
quoteBridgeRequest: parameters,
|
|
376
|
+
options: {
|
|
377
|
+
onQuoteResult: (result) => {
|
|
378
|
+
// Only called for successful quotes that are better than current best
|
|
379
|
+
console.log(`✅ Better quote from ${result.providerDappId}`)
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
if (bestQuote?.quote) {
|
|
385
|
+
// Success: we have the best available quote
|
|
386
|
+
console.log('Best quote found:', bestQuote.quote)
|
|
387
|
+
} else if (bestQuote?.error) {
|
|
388
|
+
// All providers failed, this is the first error encountered
|
|
389
|
+
console.error('All providers failed:', bestQuote.error.message)
|
|
390
|
+
console.log('Failed provider:', bestQuote.providerDappId)
|
|
391
|
+
} else {
|
|
392
|
+
// This should never happen, but good to handle
|
|
393
|
+
console.log('No quote or error returned')
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Comparison: getBestQuote vs getMultiQuotes
|
|
398
|
+
|
|
399
|
+
| Feature | `getBestQuote()` | `getMultiQuotes()` |
|
|
400
|
+
|---------|------------------|-------------------|
|
|
401
|
+
| **Returns** | Single best result | Array of all results |
|
|
402
|
+
| **Progressive Callbacks** | Only for better quotes | For all results (success & error) |
|
|
403
|
+
| **Error Handling** | Returns first error if all fail | Returns all errors in array |
|
|
404
|
+
| **Performance** | Optimized for best result only | Returns complete data set |
|
|
405
|
+
| **Use Case** | When you only need the best quote | When you need to compare all options |
|
|
406
|
+
|
|
407
|
+
Choose `getBestQuote()` when:
|
|
408
|
+
- You only need the single best quote
|
|
409
|
+
- You want real-time updates as better quotes are found
|
|
410
|
+
- You want to minimize callback overhead (only called for improvements)
|
|
411
|
+
|
|
412
|
+
Choose `getMultiQuotes()` when:
|
|
413
|
+
- You need to display all available options to users
|
|
414
|
+
- You want to analyze all provider responses
|
|
415
|
+
- You need to show provider-specific errors or statuses
|
|
416
|
+
|
|
152
417
|
## Supported Bridge Providers
|
|
153
418
|
|
|
154
419
|
- Additional bridge providers are being integrated
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { cowAppDataLatestScheme } from '@cowprotocol/sdk-app-data';
|
|
|
2
2
|
import { Amounts, OrderKind, Address, EnrichedOrder, OrderBookApi } from '@cowprotocol/sdk-order-book';
|
|
3
3
|
import { ChainInfo, TargetChainId, SupportedChainId, TokenInfo, EvmCall, ChainId, CowEnv } from '@cowprotocol/sdk-config';
|
|
4
4
|
import { QuoterParameters, TraderParameters, TradeOptionalParameters, QuoteAndPost, QuoteResults, SwapAdvancedSettings, SigningStepManager, OrderPostingResult, TradingSdk } from '@cowprotocol/sdk-trading';
|
|
5
|
-
import { AccountAddress, SignerLike, AbstractProviderAdapter } from '@cowprotocol/sdk-common';
|
|
5
|
+
import { AccountAddress, SignerLike, TTLCache, AbstractProviderAdapter } from '@cowprotocol/sdk-common';
|
|
6
6
|
import { CowShedSdk, CowShedSdkOptions } from '@cowprotocol/sdk-cow-shed';
|
|
7
7
|
|
|
8
8
|
interface BridgeProviderInfo {
|
|
@@ -327,6 +327,67 @@ interface CrossChainOrder {
|
|
|
327
327
|
tradeTxHash: string;
|
|
328
328
|
explorerUrl?: string;
|
|
329
329
|
}
|
|
330
|
+
interface MultiQuoteResult {
|
|
331
|
+
providerDappId: string;
|
|
332
|
+
quote: BridgeQuoteAndPost | null;
|
|
333
|
+
error?: Error;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Callback function called when a quote result is available from a provider
|
|
337
|
+
*/
|
|
338
|
+
type MultiQuoteProgressCallback = (result: MultiQuoteResult) => void;
|
|
339
|
+
/**
|
|
340
|
+
* Callback function called when a better quote is found
|
|
341
|
+
*/
|
|
342
|
+
type BestQuoteProgressCallback = (result: MultiQuoteResult) => void;
|
|
343
|
+
/**
|
|
344
|
+
* Options for controlling the behavior of getMultiQuotes
|
|
345
|
+
*/
|
|
346
|
+
interface MultiQuoteOptions {
|
|
347
|
+
/**
|
|
348
|
+
* Callback function called as soon as each provider returns a result
|
|
349
|
+
* Allows for progressive display of quotes without waiting for all providers
|
|
350
|
+
*/
|
|
351
|
+
onQuoteResult?: MultiQuoteProgressCallback;
|
|
352
|
+
/**
|
|
353
|
+
* Maximum time to wait for all providers to respond (in milliseconds)
|
|
354
|
+
* Default: 40000 (40 seconds)
|
|
355
|
+
*/
|
|
356
|
+
totalTimeout?: number;
|
|
357
|
+
/**
|
|
358
|
+
* Maximum time to wait for each individual provider to respond (in milliseconds)
|
|
359
|
+
* If a provider takes longer than this, it will be considered timed out
|
|
360
|
+
* Default: 20000 (20 seconds)
|
|
361
|
+
*/
|
|
362
|
+
providerTimeout?: number;
|
|
363
|
+
}
|
|
364
|
+
interface MultiQuoteRequest {
|
|
365
|
+
quoteBridgeRequest: QuoteBridgeRequest;
|
|
366
|
+
intermediateTokensCache?: TTLCache<TokenInfo[]>;
|
|
367
|
+
intermediateTokensTtl?: number;
|
|
368
|
+
providerDappIds?: string[];
|
|
369
|
+
advancedSettings?: SwapAdvancedSettings;
|
|
370
|
+
options?: MultiQuoteOptions;
|
|
371
|
+
}
|
|
372
|
+
interface MultiQuoteContext {
|
|
373
|
+
provider: BridgeProvider<BridgeQuoteResult>;
|
|
374
|
+
quoteBridgeRequest: QuoteBridgeRequest;
|
|
375
|
+
advancedSettings: SwapAdvancedSettings | undefined;
|
|
376
|
+
providerTimeout: number;
|
|
377
|
+
onQuoteResult: MultiQuoteProgressCallback | undefined;
|
|
378
|
+
}
|
|
379
|
+
interface ProviderQuoteContext extends MultiQuoteContext {
|
|
380
|
+
results: MultiQuoteResult[];
|
|
381
|
+
index: number;
|
|
382
|
+
}
|
|
383
|
+
interface BestQuoteProviderContext extends MultiQuoteContext {
|
|
384
|
+
bestResult: {
|
|
385
|
+
current: MultiQuoteResult | null;
|
|
386
|
+
};
|
|
387
|
+
firstError: {
|
|
388
|
+
current: MultiQuoteResult | null;
|
|
389
|
+
};
|
|
390
|
+
}
|
|
330
391
|
|
|
331
392
|
declare enum BridgeQuoteErrors {
|
|
332
393
|
NO_INTERMEDIATE_TOKENS = "NO_INTERMEDIATE_TOKENS",
|
|
@@ -358,6 +419,24 @@ declare function assertIsQuoteAndPost(quote: CrossChainQuoteAndPost): asserts qu
|
|
|
358
419
|
declare function getPostHooks(fullAppData?: string): cowAppDataLatestScheme.CoWHook[];
|
|
359
420
|
declare function isAppDoc(appData: unknown): appData is cowAppDataLatestScheme.AppDataRootSchema;
|
|
360
421
|
|
|
422
|
+
type BridgingSdkConfig = Required<Omit<BridgingSdkOptions, 'enableLogging' | 'cacheConfig'>>;
|
|
423
|
+
/**
|
|
424
|
+
* Cache configuration for BridgingSdk
|
|
425
|
+
*/
|
|
426
|
+
interface BridgingSdkCacheConfig {
|
|
427
|
+
/**
|
|
428
|
+
* Enable caching for target networks and buy tokens
|
|
429
|
+
*/
|
|
430
|
+
enabled: boolean;
|
|
431
|
+
/**
|
|
432
|
+
* TTL in milliseconds for getIntermediateTokens cache
|
|
433
|
+
*/
|
|
434
|
+
intermediateTokensTtl: number;
|
|
435
|
+
/**
|
|
436
|
+
* TTL in milliseconds for getBuyTokens cache
|
|
437
|
+
*/
|
|
438
|
+
buyTokensTtl: number;
|
|
439
|
+
}
|
|
361
440
|
interface BridgingSdkOptions {
|
|
362
441
|
/**
|
|
363
442
|
* Providers for the bridging.
|
|
@@ -375,6 +454,10 @@ interface BridgingSdkOptions {
|
|
|
375
454
|
* Enable logging for the bridging SDK.
|
|
376
455
|
*/
|
|
377
456
|
enableLogging?: boolean;
|
|
457
|
+
/**
|
|
458
|
+
* Cache configuration for BridgingSdk
|
|
459
|
+
*/
|
|
460
|
+
cacheConfig?: BridgingSdkCacheConfig;
|
|
378
461
|
}
|
|
379
462
|
/**
|
|
380
463
|
* Parameters for the `getOrder` method.
|
|
@@ -393,13 +476,19 @@ interface GetOrderParams {
|
|
|
393
476
|
*/
|
|
394
477
|
env?: CowEnv;
|
|
395
478
|
}
|
|
396
|
-
|
|
479
|
+
|
|
397
480
|
/**
|
|
398
481
|
* SDK for bridging for swapping tokens between different chains.
|
|
399
482
|
*/
|
|
400
483
|
declare class BridgingSdk {
|
|
401
484
|
readonly options: BridgingSdkOptions;
|
|
402
485
|
protected config: BridgingSdkConfig;
|
|
486
|
+
private cacheConfig;
|
|
487
|
+
private intermediateTokensCache;
|
|
488
|
+
private buyTokensCache;
|
|
489
|
+
private singleQuoteStrategy;
|
|
490
|
+
private multiQuoteStrategy;
|
|
491
|
+
private bestQuoteStrategy;
|
|
403
492
|
constructor(options: BridgingSdkOptions, adapter?: AbstractProviderAdapter);
|
|
404
493
|
private get provider();
|
|
405
494
|
/**
|
|
@@ -436,9 +525,57 @@ declare class BridgingSdk {
|
|
|
436
525
|
* @throws Error if no path is found
|
|
437
526
|
*/
|
|
438
527
|
getQuote(quoteBridgeRequest: QuoteBridgeRequest, advancedSettings?: SwapAdvancedSettings): Promise<CrossChainQuoteAndPost>;
|
|
528
|
+
/**
|
|
529
|
+
* Get quotes from multiple bridge providers in parallel with progressive results.
|
|
530
|
+
*
|
|
531
|
+
* This method is specifically for cross-chain bridging quotes. For single-chain swaps, use getQuote() instead.
|
|
532
|
+
*
|
|
533
|
+
* Features:
|
|
534
|
+
* - Progressive results: Use the `onQuoteResult` callback to receive quotes as soon as each provider responds
|
|
535
|
+
* - Timeout support: Configure maximum wait time for all providers and individual provider timeouts
|
|
536
|
+
* - Parallel execution: All providers are queried simultaneously for best performance
|
|
537
|
+
*
|
|
538
|
+
* @param request - The multi-quote request containing quote parameters, provider dappIds, and options
|
|
539
|
+
* @returns Array of results, one for each provider (successful quotes or errors)
|
|
540
|
+
* @throws Error if the request is for a single-chain swap (sellTokenChainId === buyTokenChainId)
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
getMultiQuotes(request: MultiQuoteRequest): Promise<MultiQuoteResult[]>;
|
|
544
|
+
/**
|
|
545
|
+
* Get the best quote from multiple bridge providers with progressive updates.
|
|
546
|
+
*
|
|
547
|
+
* This method is specifically for cross-chain bridging quotes. For single-chain swaps, use getQuote() instead.
|
|
548
|
+
*
|
|
549
|
+
* Features:
|
|
550
|
+
* - Returns only the best quote based on buyAmount after slippage
|
|
551
|
+
* - Progressive updates: Use the `onQuoteResult` callback to receive updates whenever a better quote is found
|
|
552
|
+
* - Timeout support: Configure maximum wait time for all providers and individual provider timeouts
|
|
553
|
+
* - Parallel execution: All providers are queried simultaneously for best performance
|
|
554
|
+
*
|
|
555
|
+
* @param request - The best quote request containing quote parameters, provider dappIds, and options
|
|
556
|
+
* @returns The best quote result found, or null if no successful quotes were obtained
|
|
557
|
+
* @throws Error if the request is for a single-chain swap (sellTokenChainId === buyTokenChainId)
|
|
558
|
+
*/
|
|
559
|
+
getBestQuote(request: MultiQuoteRequest): Promise<MultiQuoteResult | null>;
|
|
439
560
|
getOrder(params: GetOrderParams): Promise<CrossChainOrder | null>;
|
|
440
561
|
getOrderBridgingStatus(bridgingId: string, originChainId: SupportedChainId): Promise<BridgeStatusResult>;
|
|
441
562
|
getProviderFromAppData(fullAppData: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
563
|
+
/**
|
|
564
|
+
* Clear all caches. Useful for testing and debugging.
|
|
565
|
+
*/
|
|
566
|
+
clearCache(): void;
|
|
567
|
+
/**
|
|
568
|
+
* Clean up expired cache entries. Useful for maintenance.
|
|
569
|
+
*/
|
|
570
|
+
cleanupExpiredCache(): void;
|
|
571
|
+
/**
|
|
572
|
+
* Get cache statistics for debugging.
|
|
573
|
+
*/
|
|
574
|
+
getCacheStats(): {
|
|
575
|
+
intermediateTokens: number;
|
|
576
|
+
buyTokens: number;
|
|
577
|
+
};
|
|
578
|
+
getProviderByDappId(dappId: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
442
579
|
}
|
|
443
580
|
|
|
444
581
|
declare const RAW_PROVIDERS_FILES_PATH = "https://raw.githubusercontent.com/cowprotocol/cow-sdk/refs/heads/main/src/bridging/providers";
|
|
@@ -732,7 +869,7 @@ declare class AcrossBridgeProvider implements BridgeProvider<AcrossQuoteResult>
|
|
|
732
869
|
params: BridgingDepositParams;
|
|
733
870
|
status: BridgeStatusResult;
|
|
734
871
|
} | null>;
|
|
735
|
-
getExplorerUrl(
|
|
872
|
+
getExplorerUrl(_: string): string;
|
|
736
873
|
getStatus(bridgingId: string, originChainId: SupportedChainId): Promise<BridgeStatusResult>;
|
|
737
874
|
getCancelBridgingTx(_bridgingId: string): Promise<EvmCall>;
|
|
738
875
|
getRefundBridgingTx(_bridgingId: string): Promise<EvmCall>;
|
|
@@ -949,14 +1086,18 @@ interface AcrossStatusAPIResponse {
|
|
|
949
1086
|
};
|
|
950
1087
|
}
|
|
951
1088
|
type AcrossStatus = AcrossStatusAPIResponse['status'];
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
1089
|
+
interface BungeeApiUrlOptions {
|
|
1090
|
+
apiBaseUrl: string;
|
|
1091
|
+
manualApiBaseUrl: string;
|
|
1092
|
+
eventsApiBaseUrl: string;
|
|
1093
|
+
acrossApiBaseUrl: string;
|
|
1094
|
+
}
|
|
1095
|
+
interface BungeeApiOptions extends Partial<BungeeApiUrlOptions> {
|
|
958
1096
|
includeBridges?: SupportedBridge[];
|
|
959
1097
|
affiliate?: string;
|
|
1098
|
+
fallbackTimeoutMs?: number;
|
|
1099
|
+
apiKey?: string;
|
|
1100
|
+
customApiBaseUrl?: string;
|
|
960
1101
|
}
|
|
961
1102
|
interface IntermediateTokensParams {
|
|
962
1103
|
fromChainId: SupportedChainId;
|
|
@@ -964,8 +1105,11 @@ interface IntermediateTokensParams {
|
|
|
964
1105
|
toTokenAddress: string;
|
|
965
1106
|
includeBridges?: SupportedBridge[];
|
|
966
1107
|
}
|
|
1108
|
+
|
|
967
1109
|
declare class BungeeApi {
|
|
968
1110
|
private readonly options;
|
|
1111
|
+
private fallbackStates;
|
|
1112
|
+
private readonly fallbackTimeoutMs;
|
|
969
1113
|
constructor(options?: BungeeApiOptions);
|
|
970
1114
|
validateBridges(includeBridges: SupportedBridge[]): void;
|
|
971
1115
|
getBuyTokens(params: BuyTokensParams, bridgeParams?: {
|
|
@@ -1011,6 +1155,10 @@ declare class BungeeApi {
|
|
|
1011
1155
|
}): Promise<BungeeEvent[]>;
|
|
1012
1156
|
getAcrossStatus(depositTxHash: string): Promise<AcrossStatus>;
|
|
1013
1157
|
private getSupportedBridges;
|
|
1158
|
+
private isBungeeApi;
|
|
1159
|
+
private shouldAddApiKey;
|
|
1160
|
+
private shouldUseFallback;
|
|
1161
|
+
private enableFallback;
|
|
1014
1162
|
private shouldAddAffiliate;
|
|
1015
1163
|
private makeApiCall;
|
|
1016
1164
|
}
|
|
@@ -1048,4 +1196,4 @@ declare class BungeeBridgeProvider implements BridgeProvider<BungeeQuoteResult>
|
|
|
1048
1196
|
private isExtraGasRequired;
|
|
1049
1197
|
}
|
|
1050
1198
|
|
|
1051
|
-
export { AcrossBridgeProvider, type AcrossBridgeProviderOptions, type AcrossQuoteResult, type BridgeCallDetails, type BridgeCosts, type BridgeDeposit, type BridgeHook, BridgeOrderParsingError, type BridgeProvider, BridgeProviderError, type BridgeProviderInfo, BridgeProviderQuoteError, type BridgeQuoteAmountsAndCosts, type BridgeQuoteAndPost, BridgeQuoteErrors, type BridgeQuoteResult, type BridgeQuoteResults, BridgeStatus, type BridgeStatusResult, type BridgingDepositParams, BridgingSdk,
|
|
1199
|
+
export { AcrossBridgeProvider, type AcrossBridgeProviderOptions, type AcrossQuoteResult, type BestQuoteProgressCallback, type BestQuoteProviderContext, type BridgeCallDetails, type BridgeCosts, type BridgeDeposit, type BridgeHook, BridgeOrderParsingError, type BridgeProvider, BridgeProviderError, type BridgeProviderInfo, BridgeProviderQuoteError, type BridgeQuoteAmountsAndCosts, type BridgeQuoteAndPost, BridgeQuoteErrors, type BridgeQuoteResult, type BridgeQuoteResults, BridgeStatus, type BridgeStatusResult, type BridgingDepositParams, BridgingSdk, BungeeBridgeProvider, type BungeeBridgeProviderOptions, type BungeeQuoteResult, type BuyTokensParams, COW_SHED_PROXY_CREATION_GAS, type CrossChainOrder, type CrossChainQuoteAndPost, DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION, DEFAULT_EXTRA_GAS_PROXY_CREATION, DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION, type GetProviderBuyTokens, HOOK_DAPP_BRIDGE_PROVIDER_PREFIX, type MultiQuoteOptions, type MultiQuoteProgressCallback, type MultiQuoteRequest, type MultiQuoteResult, type ProviderQuoteContext, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, RAW_PROVIDERS_FILES_PATH, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getCrossChainOrder, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isQuoteAndPost };
|