@cowprotocol/sdk-bridging 0.1.0 → 0.2.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/dist/index.d.mts +43 -22
- package/dist/index.d.ts +43 -22
- package/dist/index.js +57 -2
- package/dist/index.mjs +57 -2
- package/package.json +8 -8
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,15 @@ 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"
|
|
340
|
-
}
|
|
341
|
-
declare class BridgeProviderQuoteError extends Error {
|
|
342
|
-
readonly context?: unknown | undefined;
|
|
343
|
-
constructor(message: BridgeQuoteErrors, context?: unknown | undefined);
|
|
344
|
-
}
|
|
345
|
-
declare class BridgeProviderError extends Error {
|
|
346
|
-
readonly context: unknown;
|
|
347
|
-
constructor(message: string, context: unknown);
|
|
353
|
+
interface MultiQuoteResult {
|
|
354
|
+
providerDappId: string;
|
|
355
|
+
quote: CrossChainQuoteAndPost | null;
|
|
356
|
+
error?: BridgeProviderError;
|
|
348
357
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
358
|
+
interface MultiQuoteRequest {
|
|
359
|
+
quoteBridgeRequest: QuoteBridgeRequest;
|
|
360
|
+
providerDappIds?: string[];
|
|
361
|
+
advancedSettings?: SwapAdvancedSettings;
|
|
352
362
|
}
|
|
353
363
|
|
|
354
364
|
declare function isBridgeQuoteAndPost(quote: CrossChainQuoteAndPost): quote is BridgeQuoteAndPost;
|
|
@@ -436,9 +446,20 @@ declare class BridgingSdk {
|
|
|
436
446
|
* @throws Error if no path is found
|
|
437
447
|
*/
|
|
438
448
|
getQuote(quoteBridgeRequest: QuoteBridgeRequest, advancedSettings?: SwapAdvancedSettings): Promise<CrossChainQuoteAndPost>;
|
|
449
|
+
/**
|
|
450
|
+
* Get quotes from multiple bridge providers in parallel.
|
|
451
|
+
*
|
|
452
|
+
* This method is specifically for cross-chain bridging quotes. For single-chain swaps, use getQuote() instead.
|
|
453
|
+
*
|
|
454
|
+
* @param request - The multi-quote request containing quote parameters and optional provider dappIds
|
|
455
|
+
* @returns Array of results, one for each provider (successful quotes or errors)
|
|
456
|
+
* @throws Error if the request is for a single-chain swap (sellTokenChainId === buyTokenChainId)
|
|
457
|
+
*/
|
|
458
|
+
getMultiQuotes(request: MultiQuoteRequest): Promise<MultiQuoteResult[]>;
|
|
439
459
|
getOrder(params: GetOrderParams): Promise<CrossChainOrder | null>;
|
|
440
460
|
getOrderBridgingStatus(bridgingId: string, originChainId: SupportedChainId): Promise<BridgeStatusResult>;
|
|
441
461
|
getProviderFromAppData(fullAppData: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
462
|
+
getProviderByDappId(dappId: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
442
463
|
}
|
|
443
464
|
|
|
444
465
|
declare const RAW_PROVIDERS_FILES_PATH = "https://raw.githubusercontent.com/cowprotocol/cow-sdk/refs/heads/main/src/bridging/providers";
|
|
@@ -1048,4 +1069,4 @@ declare class BungeeBridgeProvider implements BridgeProvider<BungeeQuoteResult>
|
|
|
1048
1069
|
private isExtraGasRequired;
|
|
1049
1070
|
}
|
|
1050
1071
|
|
|
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 };
|
|
1072
|
+
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 MultiQuoteRequest, type MultiQuoteResult, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, RAW_PROVIDERS_FILES_PATH, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getCrossChainOrder, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isQuoteAndPost };
|
package/dist/index.d.ts
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,15 @@ 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"
|
|
340
|
-
}
|
|
341
|
-
declare class BridgeProviderQuoteError extends Error {
|
|
342
|
-
readonly context?: unknown | undefined;
|
|
343
|
-
constructor(message: BridgeQuoteErrors, context?: unknown | undefined);
|
|
344
|
-
}
|
|
345
|
-
declare class BridgeProviderError extends Error {
|
|
346
|
-
readonly context: unknown;
|
|
347
|
-
constructor(message: string, context: unknown);
|
|
353
|
+
interface MultiQuoteResult {
|
|
354
|
+
providerDappId: string;
|
|
355
|
+
quote: CrossChainQuoteAndPost | null;
|
|
356
|
+
error?: BridgeProviderError;
|
|
348
357
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
358
|
+
interface MultiQuoteRequest {
|
|
359
|
+
quoteBridgeRequest: QuoteBridgeRequest;
|
|
360
|
+
providerDappIds?: string[];
|
|
361
|
+
advancedSettings?: SwapAdvancedSettings;
|
|
352
362
|
}
|
|
353
363
|
|
|
354
364
|
declare function isBridgeQuoteAndPost(quote: CrossChainQuoteAndPost): quote is BridgeQuoteAndPost;
|
|
@@ -436,9 +446,20 @@ declare class BridgingSdk {
|
|
|
436
446
|
* @throws Error if no path is found
|
|
437
447
|
*/
|
|
438
448
|
getQuote(quoteBridgeRequest: QuoteBridgeRequest, advancedSettings?: SwapAdvancedSettings): Promise<CrossChainQuoteAndPost>;
|
|
449
|
+
/**
|
|
450
|
+
* Get quotes from multiple bridge providers in parallel.
|
|
451
|
+
*
|
|
452
|
+
* This method is specifically for cross-chain bridging quotes. For single-chain swaps, use getQuote() instead.
|
|
453
|
+
*
|
|
454
|
+
* @param request - The multi-quote request containing quote parameters and optional provider dappIds
|
|
455
|
+
* @returns Array of results, one for each provider (successful quotes or errors)
|
|
456
|
+
* @throws Error if the request is for a single-chain swap (sellTokenChainId === buyTokenChainId)
|
|
457
|
+
*/
|
|
458
|
+
getMultiQuotes(request: MultiQuoteRequest): Promise<MultiQuoteResult[]>;
|
|
439
459
|
getOrder(params: GetOrderParams): Promise<CrossChainOrder | null>;
|
|
440
460
|
getOrderBridgingStatus(bridgingId: string, originChainId: SupportedChainId): Promise<BridgeStatusResult>;
|
|
441
461
|
getProviderFromAppData(fullAppData: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
462
|
+
getProviderByDappId(dappId: string): BridgeProvider<BridgeQuoteResult> | undefined;
|
|
442
463
|
}
|
|
443
464
|
|
|
444
465
|
declare const RAW_PROVIDERS_FILES_PATH = "https://raw.githubusercontent.com/cowprotocol/cow-sdk/refs/heads/main/src/bridging/providers";
|
|
@@ -1048,4 +1069,4 @@ declare class BungeeBridgeProvider implements BridgeProvider<BungeeQuoteResult>
|
|
|
1048
1069
|
private isExtraGasRequired;
|
|
1049
1070
|
}
|
|
1050
1071
|
|
|
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 };
|
|
1072
|
+
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 MultiQuoteRequest, type MultiQuoteResult, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, RAW_PROVIDERS_FILES_PATH, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getCrossChainOrder, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isQuoteAndPost };
|
package/dist/index.js
CHANGED
|
@@ -478,8 +478,8 @@ var BridgingSdk = class {
|
|
|
478
478
|
(0, import_sdk_common4.setGlobalAdapter)(adapter);
|
|
479
479
|
}
|
|
480
480
|
const { providers, ...restOptions } = options;
|
|
481
|
-
if (!providers || providers.length
|
|
482
|
-
throw new Error("
|
|
481
|
+
if (!providers || providers.length === 0) {
|
|
482
|
+
throw new Error("At least one bridge provider is required");
|
|
483
483
|
}
|
|
484
484
|
if (options.enableLogging !== void 0) {
|
|
485
485
|
(0, import_sdk_common4.enableLogging)(options.enableLogging);
|
|
@@ -561,6 +561,58 @@ var BridgingSdk = class {
|
|
|
561
561
|
});
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
|
+
/**
|
|
565
|
+
* Get quotes from multiple bridge providers in parallel.
|
|
566
|
+
*
|
|
567
|
+
* This method is specifically for cross-chain bridging quotes. For single-chain swaps, use getQuote() instead.
|
|
568
|
+
*
|
|
569
|
+
* @param request - The multi-quote request containing quote parameters and optional provider dappIds
|
|
570
|
+
* @returns Array of results, one for each provider (successful quotes or errors)
|
|
571
|
+
* @throws Error if the request is for a single-chain swap (sellTokenChainId === buyTokenChainId)
|
|
572
|
+
*/
|
|
573
|
+
async getMultiQuotes(request) {
|
|
574
|
+
const { quoteBridgeRequest, providerDappIds, advancedSettings } = request;
|
|
575
|
+
const { sellTokenChainId, buyTokenChainId } = quoteBridgeRequest;
|
|
576
|
+
if (sellTokenChainId === buyTokenChainId) {
|
|
577
|
+
throw new BridgeProviderError(
|
|
578
|
+
"getMultiQuotes() is only for cross-chain bridging. For single-chain swaps, use getQuote() instead.",
|
|
579
|
+
{ config: this.config }
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
const providersToQuery = providerDappIds ? providerDappIds.map((dappId) => {
|
|
583
|
+
const provider = this.getProviderByDappId(dappId);
|
|
584
|
+
if (!provider) {
|
|
585
|
+
throw new BridgeProviderError(
|
|
586
|
+
`Provider with dappId '${dappId}' not found. Available providers: ${this.config.providers.map((p) => p.info.dappId).join(", ")}`,
|
|
587
|
+
{ config: this.config }
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
return provider;
|
|
591
|
+
}) : this.config.providers;
|
|
592
|
+
const quotePromises = providersToQuery.map(async (provider) => {
|
|
593
|
+
try {
|
|
594
|
+
const quote = await getQuoteWithBridge({
|
|
595
|
+
swapAndBridgeRequest: quoteBridgeRequest,
|
|
596
|
+
advancedSettings,
|
|
597
|
+
tradingSdk: this.config.tradingSdk,
|
|
598
|
+
provider,
|
|
599
|
+
bridgeHookSigner: advancedSettings?.quoteSigner
|
|
600
|
+
});
|
|
601
|
+
return {
|
|
602
|
+
providerDappId: provider.info.dappId,
|
|
603
|
+
quote,
|
|
604
|
+
error: void 0
|
|
605
|
+
};
|
|
606
|
+
} catch (error) {
|
|
607
|
+
return {
|
|
608
|
+
providerDappId: provider.info.dappId,
|
|
609
|
+
quote: null,
|
|
610
|
+
error: error instanceof BridgeProviderError ? error : new BridgeProviderError(String(error), {})
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
return Promise.all(quotePromises);
|
|
615
|
+
}
|
|
564
616
|
async getOrder(params) {
|
|
565
617
|
const { orderBookApi } = this.config;
|
|
566
618
|
const { chainId, orderId, env = orderBookApi.context.env } = params;
|
|
@@ -578,6 +630,9 @@ var BridgingSdk = class {
|
|
|
578
630
|
getProviderFromAppData(fullAppData) {
|
|
579
631
|
return findBridgeProviderFromHook(fullAppData, this.getProviders());
|
|
580
632
|
}
|
|
633
|
+
getProviderByDappId(dappId) {
|
|
634
|
+
return this.config.providers.find((provider) => provider.info.dappId === dappId);
|
|
635
|
+
}
|
|
581
636
|
};
|
|
582
637
|
|
|
583
638
|
// src/providers/across/AcrossApi.ts
|
package/dist/index.mjs
CHANGED
|
@@ -436,8 +436,8 @@ var BridgingSdk = class {
|
|
|
436
436
|
setGlobalAdapter(adapter);
|
|
437
437
|
}
|
|
438
438
|
const { providers, ...restOptions } = options;
|
|
439
|
-
if (!providers || providers.length
|
|
440
|
-
throw new Error("
|
|
439
|
+
if (!providers || providers.length === 0) {
|
|
440
|
+
throw new Error("At least one bridge provider is required");
|
|
441
441
|
}
|
|
442
442
|
if (options.enableLogging !== void 0) {
|
|
443
443
|
enableLogging(options.enableLogging);
|
|
@@ -519,6 +519,58 @@ var BridgingSdk = class {
|
|
|
519
519
|
});
|
|
520
520
|
}
|
|
521
521
|
}
|
|
522
|
+
/**
|
|
523
|
+
* Get quotes from multiple bridge providers in parallel.
|
|
524
|
+
*
|
|
525
|
+
* This method is specifically for cross-chain bridging quotes. For single-chain swaps, use getQuote() instead.
|
|
526
|
+
*
|
|
527
|
+
* @param request - The multi-quote request containing quote parameters and optional provider dappIds
|
|
528
|
+
* @returns Array of results, one for each provider (successful quotes or errors)
|
|
529
|
+
* @throws Error if the request is for a single-chain swap (sellTokenChainId === buyTokenChainId)
|
|
530
|
+
*/
|
|
531
|
+
async getMultiQuotes(request) {
|
|
532
|
+
const { quoteBridgeRequest, providerDappIds, advancedSettings } = request;
|
|
533
|
+
const { sellTokenChainId, buyTokenChainId } = quoteBridgeRequest;
|
|
534
|
+
if (sellTokenChainId === buyTokenChainId) {
|
|
535
|
+
throw new BridgeProviderError(
|
|
536
|
+
"getMultiQuotes() is only for cross-chain bridging. For single-chain swaps, use getQuote() instead.",
|
|
537
|
+
{ config: this.config }
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
const providersToQuery = providerDappIds ? providerDappIds.map((dappId) => {
|
|
541
|
+
const provider = this.getProviderByDappId(dappId);
|
|
542
|
+
if (!provider) {
|
|
543
|
+
throw new BridgeProviderError(
|
|
544
|
+
`Provider with dappId '${dappId}' not found. Available providers: ${this.config.providers.map((p) => p.info.dappId).join(", ")}`,
|
|
545
|
+
{ config: this.config }
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
return provider;
|
|
549
|
+
}) : this.config.providers;
|
|
550
|
+
const quotePromises = providersToQuery.map(async (provider) => {
|
|
551
|
+
try {
|
|
552
|
+
const quote = await getQuoteWithBridge({
|
|
553
|
+
swapAndBridgeRequest: quoteBridgeRequest,
|
|
554
|
+
advancedSettings,
|
|
555
|
+
tradingSdk: this.config.tradingSdk,
|
|
556
|
+
provider,
|
|
557
|
+
bridgeHookSigner: advancedSettings?.quoteSigner
|
|
558
|
+
});
|
|
559
|
+
return {
|
|
560
|
+
providerDappId: provider.info.dappId,
|
|
561
|
+
quote,
|
|
562
|
+
error: void 0
|
|
563
|
+
};
|
|
564
|
+
} catch (error) {
|
|
565
|
+
return {
|
|
566
|
+
providerDappId: provider.info.dappId,
|
|
567
|
+
quote: null,
|
|
568
|
+
error: error instanceof BridgeProviderError ? error : new BridgeProviderError(String(error), {})
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
return Promise.all(quotePromises);
|
|
573
|
+
}
|
|
522
574
|
async getOrder(params) {
|
|
523
575
|
const { orderBookApi } = this.config;
|
|
524
576
|
const { chainId, orderId, env = orderBookApi.context.env } = params;
|
|
@@ -536,6 +588,9 @@ var BridgingSdk = class {
|
|
|
536
588
|
getProviderFromAppData(fullAppData) {
|
|
537
589
|
return findBridgeProviderFromHook(fullAppData, this.getProviders());
|
|
538
590
|
}
|
|
591
|
+
getProviderByDappId(dappId) {
|
|
592
|
+
return this.config.providers.find((provider) => provider.info.dappId === dappId);
|
|
593
|
+
}
|
|
539
594
|
};
|
|
540
595
|
|
|
541
596
|
// src/providers/across/AcrossApi.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-bridging",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Bridging for CoW Protocol",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@cowprotocol/sdk-app-data": "4.0.0",
|
|
18
|
-
"@cowprotocol/sdk-common": "0.1.0",
|
|
19
18
|
"@cowprotocol/sdk-config": "0.1.0",
|
|
20
|
-
"@cowprotocol/sdk-cow-shed": "0.1.
|
|
21
|
-
"@cowprotocol/sdk-contracts-ts": "0.1.
|
|
19
|
+
"@cowprotocol/sdk-cow-shed": "0.1.1",
|
|
20
|
+
"@cowprotocol/sdk-contracts-ts": "0.1.1",
|
|
22
21
|
"@cowprotocol/sdk-order-book": "0.1.0",
|
|
23
|
-
"@cowprotocol/sdk-trading": "0.1.
|
|
22
|
+
"@cowprotocol/sdk-trading": "0.1.1",
|
|
23
|
+
"@cowprotocol/sdk-common": "0.1.0",
|
|
24
24
|
"@cowprotocol/sdk-weiroll": "0.1.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"ts-jest": "^29.0.0",
|
|
37
37
|
"ethers": "^5.7.2",
|
|
38
38
|
"viem": "^2.28.4",
|
|
39
|
-
"@cowprotocol/sdk-order-signing": "0.1.0",
|
|
40
|
-
"@cowprotocol/sdk-ethers-v5-adapter": "0.1.0",
|
|
41
39
|
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
40
|
+
"@cowprotocol/sdk-order-signing": "0.1.1",
|
|
41
|
+
"@cowprotocol/sdk-ethers-v6-adapter": "0.1.0",
|
|
42
42
|
"@cowprotocol/sdk-viem-adapter": "0.1.0",
|
|
43
|
-
"@cowprotocol/sdk-ethers-
|
|
43
|
+
"@cowprotocol/sdk-ethers-v5-adapter": "0.1.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|