@cowprotocol/sdk-bridging 0.3.0-beta.0 → 0.3.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 +147 -43
- package/dist/index.d.ts +147 -43
- package/dist/index.js +547 -171
- package/dist/index.mjs +547 -171
- 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
|
@@ -5,6 +5,29 @@ import { QuoterParameters, TraderParameters, TradeOptionalParameters, QuoteAndPo
|
|
|
5
5
|
import { AccountAddress, SignerLike, AbstractProviderAdapter } from '@cowprotocol/sdk-common';
|
|
6
6
|
import { CowShedSdk, CowShedSdkOptions } from '@cowprotocol/sdk-cow-shed';
|
|
7
7
|
|
|
8
|
+
declare enum BridgeQuoteErrors {
|
|
9
|
+
NO_INTERMEDIATE_TOKENS = "NO_INTERMEDIATE_TOKENS",
|
|
10
|
+
API_ERROR = "API_ERROR",
|
|
11
|
+
INVALID_API_JSON_RESPONSE = "INVALID_API_JSON_RESPONSE",
|
|
12
|
+
ONLY_SELL_ORDER_SUPPORTED = "ONLY_SELL_ORDER_SUPPORTED",
|
|
13
|
+
TX_BUILD_ERROR = "TX_BUILD_ERROR",
|
|
14
|
+
QUOTE_ERROR = "QUOTE_ERROR",
|
|
15
|
+
NO_ROUTES = "NO_ROUTES",
|
|
16
|
+
INVALID_BRIDGE = "INVALID_BRIDGE"
|
|
17
|
+
}
|
|
18
|
+
declare class BridgeProviderQuoteError extends Error {
|
|
19
|
+
readonly context?: unknown | undefined;
|
|
20
|
+
constructor(message: BridgeQuoteErrors, context?: unknown | undefined);
|
|
21
|
+
}
|
|
22
|
+
declare class BridgeProviderError extends Error {
|
|
23
|
+
readonly context: unknown;
|
|
24
|
+
constructor(message: string, context: unknown);
|
|
25
|
+
}
|
|
26
|
+
declare class BridgeOrderParsingError extends Error {
|
|
27
|
+
readonly context?: unknown | undefined;
|
|
28
|
+
constructor(message: string, context?: unknown | undefined);
|
|
29
|
+
}
|
|
30
|
+
|
|
8
31
|
interface BridgeProviderInfo {
|
|
9
32
|
name: string;
|
|
10
33
|
logoUrl: string;
|
|
@@ -327,28 +350,64 @@ interface CrossChainOrder {
|
|
|
327
350
|
tradeTxHash: string;
|
|
328
351
|
explorerUrl?: string;
|
|
329
352
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
INVALID_API_JSON_RESPONSE = "INVALID_API_JSON_RESPONSE",
|
|
335
|
-
ONLY_SELL_ORDER_SUPPORTED = "ONLY_SELL_ORDER_SUPPORTED",
|
|
336
|
-
TX_BUILD_ERROR = "TX_BUILD_ERROR",
|
|
337
|
-
QUOTE_ERROR = "QUOTE_ERROR",
|
|
338
|
-
NO_ROUTES = "NO_ROUTES",
|
|
339
|
-
INVALID_BRIDGE = "INVALID_BRIDGE"
|
|
353
|
+
interface MultiQuoteResult {
|
|
354
|
+
providerDappId: string;
|
|
355
|
+
quote: BridgeQuoteAndPost | null;
|
|
356
|
+
error?: BridgeProviderError;
|
|
340
357
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
358
|
+
/**
|
|
359
|
+
* Callback function called when a quote result is available from a provider
|
|
360
|
+
*/
|
|
361
|
+
type MultiQuoteProgressCallback = (result: MultiQuoteResult) => void;
|
|
362
|
+
/**
|
|
363
|
+
* Callback function called when a better quote is found
|
|
364
|
+
*/
|
|
365
|
+
type BestQuoteProgressCallback = (result: MultiQuoteResult) => void;
|
|
366
|
+
/**
|
|
367
|
+
* Options for controlling the behavior of getMultiQuotes
|
|
368
|
+
*/
|
|
369
|
+
interface MultiQuoteOptions {
|
|
370
|
+
/**
|
|
371
|
+
* Callback function called as soon as each provider returns a result
|
|
372
|
+
* Allows for progressive display of quotes without waiting for all providers
|
|
373
|
+
*/
|
|
374
|
+
onQuoteResult?: MultiQuoteProgressCallback;
|
|
375
|
+
/**
|
|
376
|
+
* Maximum time to wait for all providers to respond (in milliseconds)
|
|
377
|
+
* Default: 40000 (40 seconds)
|
|
378
|
+
*/
|
|
379
|
+
totalTimeout?: number;
|
|
380
|
+
/**
|
|
381
|
+
* Maximum time to wait for each individual provider to respond (in milliseconds)
|
|
382
|
+
* If a provider takes longer than this, it will be considered timed out
|
|
383
|
+
* Default: 20000 (20 seconds)
|
|
384
|
+
*/
|
|
385
|
+
providerTimeout?: number;
|
|
344
386
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
387
|
+
interface MultiQuoteRequest {
|
|
388
|
+
quoteBridgeRequest: QuoteBridgeRequest;
|
|
389
|
+
providerDappIds?: string[];
|
|
390
|
+
advancedSettings?: SwapAdvancedSettings;
|
|
391
|
+
options?: MultiQuoteOptions;
|
|
348
392
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
393
|
+
interface MultiQuoteContext {
|
|
394
|
+
provider: BridgeProvider<BridgeQuoteResult>;
|
|
395
|
+
quoteBridgeRequest: QuoteBridgeRequest;
|
|
396
|
+
advancedSettings: SwapAdvancedSettings | undefined;
|
|
397
|
+
providerTimeout: number;
|
|
398
|
+
onQuoteResult: MultiQuoteProgressCallback | undefined;
|
|
399
|
+
}
|
|
400
|
+
interface ProviderQuoteContext extends MultiQuoteContext {
|
|
401
|
+
results: MultiQuoteResult[];
|
|
402
|
+
index: number;
|
|
403
|
+
}
|
|
404
|
+
interface BestQuoteProviderContext extends MultiQuoteContext {
|
|
405
|
+
bestResult: {
|
|
406
|
+
current: MultiQuoteResult | null;
|
|
407
|
+
};
|
|
408
|
+
firstError: {
|
|
409
|
+
current: MultiQuoteResult | null;
|
|
410
|
+
};
|
|
352
411
|
}
|
|
353
412
|
|
|
354
413
|
declare function isBridgeQuoteAndPost(quote: CrossChainQuoteAndPost): quote is BridgeQuoteAndPost;
|
|
@@ -358,6 +417,24 @@ declare function assertIsQuoteAndPost(quote: CrossChainQuoteAndPost): asserts qu
|
|
|
358
417
|
declare function getPostHooks(fullAppData?: string): cowAppDataLatestScheme.CoWHook[];
|
|
359
418
|
declare function isAppDoc(appData: unknown): appData is cowAppDataLatestScheme.AppDataRootSchema;
|
|
360
419
|
|
|
420
|
+
/**
|
|
421
|
+
* Parameters for the `getOrder` method.
|
|
422
|
+
*/
|
|
423
|
+
interface GetOrderParams {
|
|
424
|
+
/**
|
|
425
|
+
* Id of a network where order was settled
|
|
426
|
+
*/
|
|
427
|
+
chainId: SupportedChainId;
|
|
428
|
+
/**
|
|
429
|
+
* The unique identifier of the order.
|
|
430
|
+
*/
|
|
431
|
+
orderId: string;
|
|
432
|
+
/**
|
|
433
|
+
* The environment of the order
|
|
434
|
+
*/
|
|
435
|
+
env?: CowEnv;
|
|
436
|
+
}
|
|
437
|
+
|
|
361
438
|
interface BridgingSdkOptions {
|
|
362
439
|
/**
|
|
363
440
|
* Providers for the bridging.
|
|
@@ -376,23 +453,6 @@ interface BridgingSdkOptions {
|
|
|
376
453
|
*/
|
|
377
454
|
enableLogging?: boolean;
|
|
378
455
|
}
|
|
379
|
-
/**
|
|
380
|
-
* Parameters for the `getOrder` method.
|
|
381
|
-
*/
|
|
382
|
-
interface GetOrderParams {
|
|
383
|
-
/**
|
|
384
|
-
* Id of a network where order was settled
|
|
385
|
-
*/
|
|
386
|
-
chainId: SupportedChainId;
|
|
387
|
-
/**
|
|
388
|
-
* The unique identifier of the order.
|
|
389
|
-
*/
|
|
390
|
-
orderId: string;
|
|
391
|
-
/**
|
|
392
|
-
* The environment of the order
|
|
393
|
-
*/
|
|
394
|
-
env?: CowEnv;
|
|
395
|
-
}
|
|
396
456
|
type BridgingSdkConfig = Required<Omit<BridgingSdkOptions, 'enableLogging'>>;
|
|
397
457
|
/**
|
|
398
458
|
* SDK for bridging for swapping tokens between different chains.
|
|
@@ -436,9 +496,42 @@ declare class BridgingSdk {
|
|
|
436
496
|
* @throws Error if no path is found
|
|
437
497
|
*/
|
|
438
498
|
getQuote(quoteBridgeRequest: QuoteBridgeRequest, advancedSettings?: SwapAdvancedSettings): Promise<CrossChainQuoteAndPost>;
|
|
499
|
+
/**
|
|
500
|
+
* Get quotes from multiple bridge providers in parallel with progressive results.
|
|
501
|
+
*
|
|
502
|
+
* This method is specifically for cross-chain bridging quotes. For single-chain swaps, use getQuote() instead.
|
|
503
|
+
*
|
|
504
|
+
* Features:
|
|
505
|
+
* - Progressive results: Use the `onQuoteResult` callback to receive quotes as soon as each provider responds
|
|
506
|
+
* - Timeout support: Configure maximum wait time for all providers and individual provider timeouts
|
|
507
|
+
* - Parallel execution: All providers are queried simultaneously for best performance
|
|
508
|
+
*
|
|
509
|
+
* @param request - The multi-quote request containing quote parameters, provider dappIds, and options
|
|
510
|
+
* @returns Array of results, one for each provider (successful quotes or errors)
|
|
511
|
+
* @throws Error if the request is for a single-chain swap (sellTokenChainId === buyTokenChainId)
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
getMultiQuotes(request: MultiQuoteRequest): Promise<MultiQuoteResult[]>;
|
|
515
|
+
/**
|
|
516
|
+
* Get the best quote from multiple bridge providers with progressive updates.
|
|
517
|
+
*
|
|
518
|
+
* This method is specifically for cross-chain bridging quotes. For single-chain swaps, use getQuote() instead.
|
|
519
|
+
*
|
|
520
|
+
* Features:
|
|
521
|
+
* - Returns only the best quote based on buyAmount after slippage
|
|
522
|
+
* - Progressive updates: Use the `onQuoteResult` callback to receive updates whenever a better quote is found
|
|
523
|
+
* - Timeout support: Configure maximum wait time for all providers and individual provider timeouts
|
|
524
|
+
* - Parallel execution: All providers are queried simultaneously for best performance
|
|
525
|
+
*
|
|
526
|
+
* @param request - The best quote request containing quote parameters, provider dappIds, and options
|
|
527
|
+
* @returns The best quote result found, or null if no successful quotes were obtained
|
|
528
|
+
* @throws Error if the request is for a single-chain swap (sellTokenChainId === buyTokenChainId)
|
|
529
|
+
*/
|
|
530
|
+
getBestQuote(request: MultiQuoteRequest): Promise<MultiQuoteResult | null>;
|
|
439
531
|
getOrder(params: GetOrderParams): Promise<CrossChainOrder | null>;
|
|
440
532
|
getOrderBridgingStatus(bridgingId: string, originChainId: SupportedChainId): Promise<BridgeStatusResult>;
|
|
441
533
|
getProviderFromAppData(fullAppData: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
534
|
+
getProviderByDappId(dappId: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
442
535
|
}
|
|
443
536
|
|
|
444
537
|
declare const RAW_PROVIDERS_FILES_PATH = "https://raw.githubusercontent.com/cowprotocol/cow-sdk/refs/heads/main/src/bridging/providers";
|
|
@@ -949,14 +1042,18 @@ interface AcrossStatusAPIResponse {
|
|
|
949
1042
|
};
|
|
950
1043
|
}
|
|
951
1044
|
type AcrossStatus = AcrossStatusAPIResponse['status'];
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
1045
|
+
interface BungeeApiUrlOptions {
|
|
1046
|
+
apiBaseUrl: string;
|
|
1047
|
+
manualApiBaseUrl: string;
|
|
1048
|
+
eventsApiBaseUrl: string;
|
|
1049
|
+
acrossApiBaseUrl: string;
|
|
1050
|
+
}
|
|
1051
|
+
interface BungeeApiOptions extends Partial<BungeeApiUrlOptions> {
|
|
958
1052
|
includeBridges?: SupportedBridge[];
|
|
959
1053
|
affiliate?: string;
|
|
1054
|
+
fallbackTimeoutMs?: number;
|
|
1055
|
+
apiKey?: string;
|
|
1056
|
+
customApiBaseUrl?: string;
|
|
960
1057
|
}
|
|
961
1058
|
interface IntermediateTokensParams {
|
|
962
1059
|
fromChainId: SupportedChainId;
|
|
@@ -964,8 +1061,11 @@ interface IntermediateTokensParams {
|
|
|
964
1061
|
toTokenAddress: string;
|
|
965
1062
|
includeBridges?: SupportedBridge[];
|
|
966
1063
|
}
|
|
1064
|
+
|
|
967
1065
|
declare class BungeeApi {
|
|
968
1066
|
private readonly options;
|
|
1067
|
+
private fallbackStates;
|
|
1068
|
+
private readonly fallbackTimeoutMs;
|
|
969
1069
|
constructor(options?: BungeeApiOptions);
|
|
970
1070
|
validateBridges(includeBridges: SupportedBridge[]): void;
|
|
971
1071
|
getBuyTokens(params: BuyTokensParams, bridgeParams?: {
|
|
@@ -1011,6 +1111,10 @@ declare class BungeeApi {
|
|
|
1011
1111
|
}): Promise<BungeeEvent[]>;
|
|
1012
1112
|
getAcrossStatus(depositTxHash: string): Promise<AcrossStatus>;
|
|
1013
1113
|
private getSupportedBridges;
|
|
1114
|
+
private isBungeeApi;
|
|
1115
|
+
private shouldAddApiKey;
|
|
1116
|
+
private shouldUseFallback;
|
|
1117
|
+
private enableFallback;
|
|
1014
1118
|
private shouldAddAffiliate;
|
|
1015
1119
|
private makeApiCall;
|
|
1016
1120
|
}
|
|
@@ -1048,4 +1152,4 @@ declare class BungeeBridgeProvider implements BridgeProvider<BungeeQuoteResult>
|
|
|
1048
1152
|
private isExtraGasRequired;
|
|
1049
1153
|
}
|
|
1050
1154
|
|
|
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, type BridgingSdkConfig, type BridgingSdkOptions, 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
|
|
1155
|
+
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, type BridgingSdkConfig, type BridgingSdkOptions, 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 };
|