@cowprotocol/sdk-bridging 0.3.2 → 0.3.3-beta.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 +0 -265
- package/dist/index.d.mts +24 -128
- package/dist/index.d.ts +24 -128
- package/dist/index.js +170 -546
- package/dist/index.mjs +170 -546
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -149,271 +149,6 @@ 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
|
-
|
|
417
152
|
## Supported Bridge Providers
|
|
418
153
|
|
|
419
154
|
- Additional bridge providers are being integrated
|
package/dist/index.d.mts
CHANGED
|
@@ -327,65 +327,6 @@ 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
|
-
providerDappIds?: string[];
|
|
367
|
-
advancedSettings?: SwapAdvancedSettings;
|
|
368
|
-
options?: MultiQuoteOptions;
|
|
369
|
-
}
|
|
370
|
-
interface MultiQuoteContext {
|
|
371
|
-
provider: BridgeProvider<BridgeQuoteResult>;
|
|
372
|
-
quoteBridgeRequest: QuoteBridgeRequest;
|
|
373
|
-
advancedSettings: SwapAdvancedSettings | undefined;
|
|
374
|
-
providerTimeout: number;
|
|
375
|
-
onQuoteResult: MultiQuoteProgressCallback | undefined;
|
|
376
|
-
}
|
|
377
|
-
interface ProviderQuoteContext extends MultiQuoteContext {
|
|
378
|
-
results: MultiQuoteResult[];
|
|
379
|
-
index: number;
|
|
380
|
-
}
|
|
381
|
-
interface BestQuoteProviderContext extends MultiQuoteContext {
|
|
382
|
-
bestResult: {
|
|
383
|
-
current: MultiQuoteResult | null;
|
|
384
|
-
};
|
|
385
|
-
firstError: {
|
|
386
|
-
current: MultiQuoteResult | null;
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
330
|
|
|
390
331
|
declare enum BridgeQuoteErrors {
|
|
391
332
|
NO_INTERMEDIATE_TOKENS = "NO_INTERMEDIATE_TOKENS",
|
|
@@ -417,24 +358,6 @@ declare function assertIsQuoteAndPost(quote: CrossChainQuoteAndPost): asserts qu
|
|
|
417
358
|
declare function getPostHooks(fullAppData?: string): cowAppDataLatestScheme.CoWHook[];
|
|
418
359
|
declare function isAppDoc(appData: unknown): appData is cowAppDataLatestScheme.AppDataRootSchema;
|
|
419
360
|
|
|
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
|
-
|
|
438
361
|
interface BridgingSdkOptions {
|
|
439
362
|
/**
|
|
440
363
|
* Providers for the bridging.
|
|
@@ -453,6 +376,23 @@ interface BridgingSdkOptions {
|
|
|
453
376
|
*/
|
|
454
377
|
enableLogging?: boolean;
|
|
455
378
|
}
|
|
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
|
+
}
|
|
456
396
|
type BridgingSdkConfig = Required<Omit<BridgingSdkOptions, 'enableLogging'>>;
|
|
457
397
|
/**
|
|
458
398
|
* SDK for bridging for swapping tokens between different chains.
|
|
@@ -496,42 +436,9 @@ declare class BridgingSdk {
|
|
|
496
436
|
* @throws Error if no path is found
|
|
497
437
|
*/
|
|
498
438
|
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>;
|
|
531
439
|
getOrder(params: GetOrderParams): Promise<CrossChainOrder | null>;
|
|
532
440
|
getOrderBridgingStatus(bridgingId: string, originChainId: SupportedChainId): Promise<BridgeStatusResult>;
|
|
533
441
|
getProviderFromAppData(fullAppData: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
534
|
-
getProviderByDappId(dappId: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
535
442
|
}
|
|
536
443
|
|
|
537
444
|
declare const RAW_PROVIDERS_FILES_PATH = "https://raw.githubusercontent.com/cowprotocol/cow-sdk/refs/heads/main/src/bridging/providers";
|
|
@@ -1042,18 +949,14 @@ interface AcrossStatusAPIResponse {
|
|
|
1042
949
|
};
|
|
1043
950
|
}
|
|
1044
951
|
type AcrossStatus = AcrossStatusAPIResponse['status'];
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
interface BungeeApiOptions extends Partial<BungeeApiUrlOptions> {
|
|
952
|
+
|
|
953
|
+
interface BungeeApiOptions {
|
|
954
|
+
apiBaseUrl?: string;
|
|
955
|
+
manualApiBaseUrl?: string;
|
|
956
|
+
eventsApiBaseUrl?: string;
|
|
957
|
+
acrossApiBaseUrl?: string;
|
|
1052
958
|
includeBridges?: SupportedBridge[];
|
|
1053
959
|
affiliate?: string;
|
|
1054
|
-
fallbackTimeoutMs?: number;
|
|
1055
|
-
apiKey?: string;
|
|
1056
|
-
customApiBaseUrl?: string;
|
|
1057
960
|
}
|
|
1058
961
|
interface IntermediateTokensParams {
|
|
1059
962
|
fromChainId: SupportedChainId;
|
|
@@ -1061,11 +964,8 @@ interface IntermediateTokensParams {
|
|
|
1061
964
|
toTokenAddress: string;
|
|
1062
965
|
includeBridges?: SupportedBridge[];
|
|
1063
966
|
}
|
|
1064
|
-
|
|
1065
967
|
declare class BungeeApi {
|
|
1066
968
|
private readonly options;
|
|
1067
|
-
private fallbackStates;
|
|
1068
|
-
private readonly fallbackTimeoutMs;
|
|
1069
969
|
constructor(options?: BungeeApiOptions);
|
|
1070
970
|
validateBridges(includeBridges: SupportedBridge[]): void;
|
|
1071
971
|
getBuyTokens(params: BuyTokensParams, bridgeParams?: {
|
|
@@ -1111,10 +1011,6 @@ declare class BungeeApi {
|
|
|
1111
1011
|
}): Promise<BungeeEvent[]>;
|
|
1112
1012
|
getAcrossStatus(depositTxHash: string): Promise<AcrossStatus>;
|
|
1113
1013
|
private getSupportedBridges;
|
|
1114
|
-
private isBungeeApi;
|
|
1115
|
-
private shouldAddApiKey;
|
|
1116
|
-
private shouldUseFallback;
|
|
1117
|
-
private enableFallback;
|
|
1118
1014
|
private shouldAddAffiliate;
|
|
1119
1015
|
private makeApiCall;
|
|
1120
1016
|
}
|
|
@@ -1152,4 +1048,4 @@ declare class BungeeBridgeProvider implements BridgeProvider<BungeeQuoteResult>
|
|
|
1152
1048
|
private isExtraGasRequired;
|
|
1153
1049
|
}
|
|
1154
1050
|
|
|
1155
|
-
export { AcrossBridgeProvider, type AcrossBridgeProviderOptions, type AcrossQuoteResult, type
|
|
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 GetOrderParams, type GetProviderBuyTokens, HOOK_DAPP_BRIDGE_PROVIDER_PREFIX, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, RAW_PROVIDERS_FILES_PATH, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getCrossChainOrder, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isQuoteAndPost };
|
package/dist/index.d.ts
CHANGED
|
@@ -327,65 +327,6 @@ 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
|
-
providerDappIds?: string[];
|
|
367
|
-
advancedSettings?: SwapAdvancedSettings;
|
|
368
|
-
options?: MultiQuoteOptions;
|
|
369
|
-
}
|
|
370
|
-
interface MultiQuoteContext {
|
|
371
|
-
provider: BridgeProvider<BridgeQuoteResult>;
|
|
372
|
-
quoteBridgeRequest: QuoteBridgeRequest;
|
|
373
|
-
advancedSettings: SwapAdvancedSettings | undefined;
|
|
374
|
-
providerTimeout: number;
|
|
375
|
-
onQuoteResult: MultiQuoteProgressCallback | undefined;
|
|
376
|
-
}
|
|
377
|
-
interface ProviderQuoteContext extends MultiQuoteContext {
|
|
378
|
-
results: MultiQuoteResult[];
|
|
379
|
-
index: number;
|
|
380
|
-
}
|
|
381
|
-
interface BestQuoteProviderContext extends MultiQuoteContext {
|
|
382
|
-
bestResult: {
|
|
383
|
-
current: MultiQuoteResult | null;
|
|
384
|
-
};
|
|
385
|
-
firstError: {
|
|
386
|
-
current: MultiQuoteResult | null;
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
330
|
|
|
390
331
|
declare enum BridgeQuoteErrors {
|
|
391
332
|
NO_INTERMEDIATE_TOKENS = "NO_INTERMEDIATE_TOKENS",
|
|
@@ -417,24 +358,6 @@ declare function assertIsQuoteAndPost(quote: CrossChainQuoteAndPost): asserts qu
|
|
|
417
358
|
declare function getPostHooks(fullAppData?: string): cowAppDataLatestScheme.CoWHook[];
|
|
418
359
|
declare function isAppDoc(appData: unknown): appData is cowAppDataLatestScheme.AppDataRootSchema;
|
|
419
360
|
|
|
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
|
-
|
|
438
361
|
interface BridgingSdkOptions {
|
|
439
362
|
/**
|
|
440
363
|
* Providers for the bridging.
|
|
@@ -453,6 +376,23 @@ interface BridgingSdkOptions {
|
|
|
453
376
|
*/
|
|
454
377
|
enableLogging?: boolean;
|
|
455
378
|
}
|
|
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
|
+
}
|
|
456
396
|
type BridgingSdkConfig = Required<Omit<BridgingSdkOptions, 'enableLogging'>>;
|
|
457
397
|
/**
|
|
458
398
|
* SDK for bridging for swapping tokens between different chains.
|
|
@@ -496,42 +436,9 @@ declare class BridgingSdk {
|
|
|
496
436
|
* @throws Error if no path is found
|
|
497
437
|
*/
|
|
498
438
|
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>;
|
|
531
439
|
getOrder(params: GetOrderParams): Promise<CrossChainOrder | null>;
|
|
532
440
|
getOrderBridgingStatus(bridgingId: string, originChainId: SupportedChainId): Promise<BridgeStatusResult>;
|
|
533
441
|
getProviderFromAppData(fullAppData: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
534
|
-
getProviderByDappId(dappId: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
535
442
|
}
|
|
536
443
|
|
|
537
444
|
declare const RAW_PROVIDERS_FILES_PATH = "https://raw.githubusercontent.com/cowprotocol/cow-sdk/refs/heads/main/src/bridging/providers";
|
|
@@ -1042,18 +949,14 @@ interface AcrossStatusAPIResponse {
|
|
|
1042
949
|
};
|
|
1043
950
|
}
|
|
1044
951
|
type AcrossStatus = AcrossStatusAPIResponse['status'];
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
interface BungeeApiOptions extends Partial<BungeeApiUrlOptions> {
|
|
952
|
+
|
|
953
|
+
interface BungeeApiOptions {
|
|
954
|
+
apiBaseUrl?: string;
|
|
955
|
+
manualApiBaseUrl?: string;
|
|
956
|
+
eventsApiBaseUrl?: string;
|
|
957
|
+
acrossApiBaseUrl?: string;
|
|
1052
958
|
includeBridges?: SupportedBridge[];
|
|
1053
959
|
affiliate?: string;
|
|
1054
|
-
fallbackTimeoutMs?: number;
|
|
1055
|
-
apiKey?: string;
|
|
1056
|
-
customApiBaseUrl?: string;
|
|
1057
960
|
}
|
|
1058
961
|
interface IntermediateTokensParams {
|
|
1059
962
|
fromChainId: SupportedChainId;
|
|
@@ -1061,11 +964,8 @@ interface IntermediateTokensParams {
|
|
|
1061
964
|
toTokenAddress: string;
|
|
1062
965
|
includeBridges?: SupportedBridge[];
|
|
1063
966
|
}
|
|
1064
|
-
|
|
1065
967
|
declare class BungeeApi {
|
|
1066
968
|
private readonly options;
|
|
1067
|
-
private fallbackStates;
|
|
1068
|
-
private readonly fallbackTimeoutMs;
|
|
1069
969
|
constructor(options?: BungeeApiOptions);
|
|
1070
970
|
validateBridges(includeBridges: SupportedBridge[]): void;
|
|
1071
971
|
getBuyTokens(params: BuyTokensParams, bridgeParams?: {
|
|
@@ -1111,10 +1011,6 @@ declare class BungeeApi {
|
|
|
1111
1011
|
}): Promise<BungeeEvent[]>;
|
|
1112
1012
|
getAcrossStatus(depositTxHash: string): Promise<AcrossStatus>;
|
|
1113
1013
|
private getSupportedBridges;
|
|
1114
|
-
private isBungeeApi;
|
|
1115
|
-
private shouldAddApiKey;
|
|
1116
|
-
private shouldUseFallback;
|
|
1117
|
-
private enableFallback;
|
|
1118
1014
|
private shouldAddAffiliate;
|
|
1119
1015
|
private makeApiCall;
|
|
1120
1016
|
}
|
|
@@ -1152,4 +1048,4 @@ declare class BungeeBridgeProvider implements BridgeProvider<BungeeQuoteResult>
|
|
|
1152
1048
|
private isExtraGasRequired;
|
|
1153
1049
|
}
|
|
1154
1050
|
|
|
1155
|
-
export { AcrossBridgeProvider, type AcrossBridgeProviderOptions, type AcrossQuoteResult, type
|
|
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 GetOrderParams, type GetProviderBuyTokens, HOOK_DAPP_BRIDGE_PROVIDER_PREFIX, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, RAW_PROVIDERS_FILES_PATH, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getCrossChainOrder, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isQuoteAndPost };
|