@cowprotocol/sdk-bridging 0.1.0-monorepo.3 → 0.2.0-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/dist/index.d.mts +31 -16
- package/dist/index.d.ts +31 -16
- package/dist/index.js +92 -17
- package/dist/index.mjs +98 -23
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
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';
|
|
@@ -75,7 +75,7 @@ interface BridgeQuoteResult {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
interface BridgeHook {
|
|
78
|
-
postHook:
|
|
78
|
+
postHook: cowAppDataLatestScheme.CoWHook;
|
|
79
79
|
recipient: string;
|
|
80
80
|
}
|
|
81
81
|
declare enum BridgeStatus {
|
|
@@ -107,6 +107,10 @@ interface BuyTokensParams {
|
|
|
107
107
|
sellChainId?: SupportedChainId;
|
|
108
108
|
sellTokenAddress?: string;
|
|
109
109
|
}
|
|
110
|
+
interface GetProviderBuyTokens {
|
|
111
|
+
tokens: TokenInfo[];
|
|
112
|
+
isRouteAvailable: boolean;
|
|
113
|
+
}
|
|
110
114
|
/**
|
|
111
115
|
* A bridge deposit. It includes the provideer information, sell amount and the minimum buy amount.
|
|
112
116
|
*
|
|
@@ -127,7 +131,7 @@ interface BridgeProvider<Q extends BridgeQuoteResult> {
|
|
|
127
131
|
/**
|
|
128
132
|
* Get supported tokens for a chain
|
|
129
133
|
*/
|
|
130
|
-
getBuyTokens(params: BuyTokensParams): Promise<
|
|
134
|
+
getBuyTokens(params: BuyTokensParams): Promise<GetProviderBuyTokens>;
|
|
131
135
|
/**
|
|
132
136
|
* Get intermediate tokens given a quote request.
|
|
133
137
|
*
|
|
@@ -162,8 +166,14 @@ interface BridgeProvider<Q extends BridgeQuoteResult> {
|
|
|
162
166
|
* 2. The final amount could affect hook gas costs
|
|
163
167
|
*
|
|
164
168
|
* By estimating gas costs independently, we can resolve this dependency cycle.
|
|
169
|
+
* For some providers, the `extraGas` parameter adds additional gas‐unit buffer to the hook
|
|
170
|
+
* and `extraGasProxyCreation` parameter adds additional gas‐unit buffer for the proxy creation
|
|
171
|
+
* (see DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION and DEFAULT_EXTRA_GAS_PROXY_CREATION).
|
|
165
172
|
*/
|
|
166
|
-
getGasLimitEstimationForHook(request: Omit<QuoteBridgeRequest, 'amount'>
|
|
173
|
+
getGasLimitEstimationForHook(request: Omit<QuoteBridgeRequest, 'amount'> & {
|
|
174
|
+
extraGas?: number;
|
|
175
|
+
extraGasProxyCreation?: number;
|
|
176
|
+
}): Promise<number>;
|
|
167
177
|
/**
|
|
168
178
|
* Get a pre-authorized hook for initiating a bridge.
|
|
169
179
|
*
|
|
@@ -185,7 +195,7 @@ interface BridgeProvider<Q extends BridgeQuoteResult> {
|
|
|
185
195
|
*
|
|
186
196
|
* @param hook - The bridge hook
|
|
187
197
|
*/
|
|
188
|
-
decodeBridgeHook(hook:
|
|
198
|
+
decodeBridgeHook(hook: cowAppDataLatestScheme.CoWHook): Promise<BridgeDeposit>;
|
|
189
199
|
/**
|
|
190
200
|
* Get the identifier of the bridging transaction from the settlement transaction.
|
|
191
201
|
* @param chainId
|
|
@@ -345,8 +355,8 @@ declare function isBridgeQuoteAndPost(quote: CrossChainQuoteAndPost): quote is B
|
|
|
345
355
|
declare function isQuoteAndPost(quote: CrossChainQuoteAndPost): quote is QuoteAndPost;
|
|
346
356
|
declare function assertIsBridgeQuoteAndPost(quote: CrossChainQuoteAndPost): asserts quote is BridgeQuoteAndPost;
|
|
347
357
|
declare function assertIsQuoteAndPost(quote: CrossChainQuoteAndPost): asserts quote is QuoteAndPost;
|
|
348
|
-
declare function getPostHooks(fullAppData?: string):
|
|
349
|
-
declare function isAppDoc(appData: unknown): appData is
|
|
358
|
+
declare function getPostHooks(fullAppData?: string): cowAppDataLatestScheme.CoWHook[];
|
|
359
|
+
declare function isAppDoc(appData: unknown): appData is cowAppDataLatestScheme.AppDataRootSchema;
|
|
350
360
|
|
|
351
361
|
interface BridgingSdkOptions {
|
|
352
362
|
/**
|
|
@@ -390,7 +400,7 @@ type BridgingSdkConfig = Required<Omit<BridgingSdkOptions, 'enableLogging'>>;
|
|
|
390
400
|
declare class BridgingSdk {
|
|
391
401
|
readonly options: BridgingSdkOptions;
|
|
392
402
|
protected config: BridgingSdkConfig;
|
|
393
|
-
constructor(options: BridgingSdkOptions);
|
|
403
|
+
constructor(options: BridgingSdkOptions, adapter?: AbstractProviderAdapter);
|
|
394
404
|
private get provider();
|
|
395
405
|
/**
|
|
396
406
|
* Get the providers for the bridging.
|
|
@@ -409,7 +419,7 @@ declare class BridgingSdk {
|
|
|
409
419
|
|
|
410
420
|
* @param params
|
|
411
421
|
*/
|
|
412
|
-
getBuyTokens(params: BuyTokensParams): Promise<
|
|
422
|
+
getBuyTokens(params: BuyTokensParams): Promise<GetProviderBuyTokens>;
|
|
413
423
|
/**
|
|
414
424
|
* Get quote details, including a callback function to post the order on-chain.
|
|
415
425
|
*
|
|
@@ -433,7 +443,9 @@ declare class BridgingSdk {
|
|
|
433
443
|
|
|
434
444
|
declare const RAW_PROVIDERS_FILES_PATH = "https://raw.githubusercontent.com/cowprotocol/cow-sdk/refs/heads/main/src/bridging/providers";
|
|
435
445
|
declare const DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION = 240000;
|
|
446
|
+
declare const DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION = 200000;
|
|
436
447
|
declare const COW_SHED_PROXY_CREATION_GAS = 360000;
|
|
448
|
+
declare const DEFAULT_EXTRA_GAS_PROXY_CREATION = 400000;
|
|
437
449
|
declare const HOOK_DAPP_BRIDGE_PROVIDER_PREFIX = "cow-sdk://bridging/providers";
|
|
438
450
|
|
|
439
451
|
interface GetCrossChainOrderParams {
|
|
@@ -709,13 +721,13 @@ declare class AcrossBridgeProvider implements BridgeProvider<AcrossQuoteResult>
|
|
|
709
721
|
constructor(options?: AcrossBridgeProviderOptions, _adapter?: AbstractProviderAdapter);
|
|
710
722
|
info: BridgeProviderInfo;
|
|
711
723
|
getNetworks(): Promise<ChainInfo[]>;
|
|
712
|
-
getBuyTokens(params: BuyTokensParams): Promise<
|
|
724
|
+
getBuyTokens(params: BuyTokensParams): Promise<GetProviderBuyTokens>;
|
|
713
725
|
getIntermediateTokens(request: QuoteBridgeRequest): Promise<TokenInfo[]>;
|
|
714
726
|
getQuote(request: QuoteBridgeRequest): Promise<AcrossQuoteResult>;
|
|
715
727
|
getUnsignedBridgeCall(request: QuoteBridgeRequest, quote: AcrossQuoteResult): Promise<EvmCall>;
|
|
716
728
|
getGasLimitEstimationForHook(request: QuoteBridgeRequest): Promise<number>;
|
|
717
729
|
getSignedHook(chainId: SupportedChainId, unsignedCall: EvmCall, bridgeHookNonce: string, deadline: bigint, hookGasLimit: number, signer?: SignerLike): Promise<BridgeHook>;
|
|
718
|
-
decodeBridgeHook(_hook:
|
|
730
|
+
decodeBridgeHook(_hook: cowAppDataLatestScheme.CoWHook): Promise<BridgeDeposit>;
|
|
719
731
|
getBridgingParams(chainId: ChainId, orderUid: string, txHash: string): Promise<{
|
|
720
732
|
params: BridgingDepositParams;
|
|
721
733
|
status: BridgeStatusResult;
|
|
@@ -727,7 +739,7 @@ declare class AcrossBridgeProvider implements BridgeProvider<AcrossQuoteResult>
|
|
|
727
739
|
private getSupportedTokensState;
|
|
728
740
|
}
|
|
729
741
|
|
|
730
|
-
type SupportedBridge = 'across' | 'cctp';
|
|
742
|
+
type SupportedBridge = 'across' | 'cctp' | 'gnosis-native-bridge';
|
|
731
743
|
interface BungeeQuoteAPIRequest {
|
|
732
744
|
userAddress: string;
|
|
733
745
|
originChainId: string;
|
|
@@ -834,7 +846,8 @@ interface BungeeQuoteAPIResponse {
|
|
|
834
846
|
}
|
|
835
847
|
declare enum BungeeBridge {
|
|
836
848
|
'Across' = "across",
|
|
837
|
-
'CircleCCTP' = "cctp"
|
|
849
|
+
'CircleCCTP' = "cctp",
|
|
850
|
+
'GnosisNative' = "gnosis-native-bridge"
|
|
838
851
|
}
|
|
839
852
|
interface BungeeQuote {
|
|
840
853
|
originChainId: number;
|
|
@@ -943,6 +956,7 @@ interface BungeeApiOptions {
|
|
|
943
956
|
eventsApiBaseUrl?: string;
|
|
944
957
|
acrossApiBaseUrl?: string;
|
|
945
958
|
includeBridges?: SupportedBridge[];
|
|
959
|
+
affiliate?: string;
|
|
946
960
|
}
|
|
947
961
|
interface IntermediateTokensParams {
|
|
948
962
|
fromChainId: SupportedChainId;
|
|
@@ -1015,7 +1029,7 @@ declare class BungeeBridgeProvider implements BridgeProvider<BungeeQuoteResult>
|
|
|
1015
1029
|
constructor(options: BungeeBridgeProviderOptions, _adapter?: AbstractProviderAdapter);
|
|
1016
1030
|
info: BridgeProviderInfo;
|
|
1017
1031
|
getNetworks(): Promise<ChainInfo[]>;
|
|
1018
|
-
getBuyTokens(params: BuyTokensParams): Promise<
|
|
1032
|
+
getBuyTokens(params: BuyTokensParams): Promise<GetProviderBuyTokens>;
|
|
1019
1033
|
getIntermediateTokens(request: QuoteBridgeRequest): Promise<TokenInfo[]>;
|
|
1020
1034
|
getQuote(request: QuoteBridgeRequest): Promise<BungeeQuoteResult>;
|
|
1021
1035
|
getUnsignedBridgeCall(request: QuoteBridgeRequest, quote: BungeeQuoteResult): Promise<EvmCall>;
|
|
@@ -1025,11 +1039,12 @@ declare class BungeeBridgeProvider implements BridgeProvider<BungeeQuoteResult>
|
|
|
1025
1039
|
params: BridgingDepositParams;
|
|
1026
1040
|
status: BridgeStatusResult;
|
|
1027
1041
|
} | null>;
|
|
1028
|
-
decodeBridgeHook(_hook:
|
|
1042
|
+
decodeBridgeHook(_hook: cowAppDataLatestScheme.CoWHook): Promise<BridgeDeposit>;
|
|
1029
1043
|
getExplorerUrl(bridgingId: string): string;
|
|
1030
1044
|
getStatus(_bridgingId: string): Promise<BridgeStatusResult>;
|
|
1031
1045
|
getCancelBridgingTx(_bridgingId: string): Promise<EvmCall>;
|
|
1032
1046
|
getRefundBridgingTx(_bridgingId: string): Promise<EvmCall>;
|
|
1047
|
+
private isExtraGasRequired;
|
|
1033
1048
|
}
|
|
1034
1049
|
|
|
1035
|
-
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_GAS_COST_FOR_HOOK_ESTIMATION, type GetOrderParams, HOOK_DAPP_BRIDGE_PROVIDER_PREFIX, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, RAW_PROVIDERS_FILES_PATH, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getCrossChainOrder, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isQuoteAndPost };
|
|
1050
|
+
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
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';
|
|
@@ -75,7 +75,7 @@ interface BridgeQuoteResult {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
interface BridgeHook {
|
|
78
|
-
postHook:
|
|
78
|
+
postHook: cowAppDataLatestScheme.CoWHook;
|
|
79
79
|
recipient: string;
|
|
80
80
|
}
|
|
81
81
|
declare enum BridgeStatus {
|
|
@@ -107,6 +107,10 @@ interface BuyTokensParams {
|
|
|
107
107
|
sellChainId?: SupportedChainId;
|
|
108
108
|
sellTokenAddress?: string;
|
|
109
109
|
}
|
|
110
|
+
interface GetProviderBuyTokens {
|
|
111
|
+
tokens: TokenInfo[];
|
|
112
|
+
isRouteAvailable: boolean;
|
|
113
|
+
}
|
|
110
114
|
/**
|
|
111
115
|
* A bridge deposit. It includes the provideer information, sell amount and the minimum buy amount.
|
|
112
116
|
*
|
|
@@ -127,7 +131,7 @@ interface BridgeProvider<Q extends BridgeQuoteResult> {
|
|
|
127
131
|
/**
|
|
128
132
|
* Get supported tokens for a chain
|
|
129
133
|
*/
|
|
130
|
-
getBuyTokens(params: BuyTokensParams): Promise<
|
|
134
|
+
getBuyTokens(params: BuyTokensParams): Promise<GetProviderBuyTokens>;
|
|
131
135
|
/**
|
|
132
136
|
* Get intermediate tokens given a quote request.
|
|
133
137
|
*
|
|
@@ -162,8 +166,14 @@ interface BridgeProvider<Q extends BridgeQuoteResult> {
|
|
|
162
166
|
* 2. The final amount could affect hook gas costs
|
|
163
167
|
*
|
|
164
168
|
* By estimating gas costs independently, we can resolve this dependency cycle.
|
|
169
|
+
* For some providers, the `extraGas` parameter adds additional gas‐unit buffer to the hook
|
|
170
|
+
* and `extraGasProxyCreation` parameter adds additional gas‐unit buffer for the proxy creation
|
|
171
|
+
* (see DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION and DEFAULT_EXTRA_GAS_PROXY_CREATION).
|
|
165
172
|
*/
|
|
166
|
-
getGasLimitEstimationForHook(request: Omit<QuoteBridgeRequest, 'amount'>
|
|
173
|
+
getGasLimitEstimationForHook(request: Omit<QuoteBridgeRequest, 'amount'> & {
|
|
174
|
+
extraGas?: number;
|
|
175
|
+
extraGasProxyCreation?: number;
|
|
176
|
+
}): Promise<number>;
|
|
167
177
|
/**
|
|
168
178
|
* Get a pre-authorized hook for initiating a bridge.
|
|
169
179
|
*
|
|
@@ -185,7 +195,7 @@ interface BridgeProvider<Q extends BridgeQuoteResult> {
|
|
|
185
195
|
*
|
|
186
196
|
* @param hook - The bridge hook
|
|
187
197
|
*/
|
|
188
|
-
decodeBridgeHook(hook:
|
|
198
|
+
decodeBridgeHook(hook: cowAppDataLatestScheme.CoWHook): Promise<BridgeDeposit>;
|
|
189
199
|
/**
|
|
190
200
|
* Get the identifier of the bridging transaction from the settlement transaction.
|
|
191
201
|
* @param chainId
|
|
@@ -345,8 +355,8 @@ declare function isBridgeQuoteAndPost(quote: CrossChainQuoteAndPost): quote is B
|
|
|
345
355
|
declare function isQuoteAndPost(quote: CrossChainQuoteAndPost): quote is QuoteAndPost;
|
|
346
356
|
declare function assertIsBridgeQuoteAndPost(quote: CrossChainQuoteAndPost): asserts quote is BridgeQuoteAndPost;
|
|
347
357
|
declare function assertIsQuoteAndPost(quote: CrossChainQuoteAndPost): asserts quote is QuoteAndPost;
|
|
348
|
-
declare function getPostHooks(fullAppData?: string):
|
|
349
|
-
declare function isAppDoc(appData: unknown): appData is
|
|
358
|
+
declare function getPostHooks(fullAppData?: string): cowAppDataLatestScheme.CoWHook[];
|
|
359
|
+
declare function isAppDoc(appData: unknown): appData is cowAppDataLatestScheme.AppDataRootSchema;
|
|
350
360
|
|
|
351
361
|
interface BridgingSdkOptions {
|
|
352
362
|
/**
|
|
@@ -390,7 +400,7 @@ type BridgingSdkConfig = Required<Omit<BridgingSdkOptions, 'enableLogging'>>;
|
|
|
390
400
|
declare class BridgingSdk {
|
|
391
401
|
readonly options: BridgingSdkOptions;
|
|
392
402
|
protected config: BridgingSdkConfig;
|
|
393
|
-
constructor(options: BridgingSdkOptions);
|
|
403
|
+
constructor(options: BridgingSdkOptions, adapter?: AbstractProviderAdapter);
|
|
394
404
|
private get provider();
|
|
395
405
|
/**
|
|
396
406
|
* Get the providers for the bridging.
|
|
@@ -409,7 +419,7 @@ declare class BridgingSdk {
|
|
|
409
419
|
|
|
410
420
|
* @param params
|
|
411
421
|
*/
|
|
412
|
-
getBuyTokens(params: BuyTokensParams): Promise<
|
|
422
|
+
getBuyTokens(params: BuyTokensParams): Promise<GetProviderBuyTokens>;
|
|
413
423
|
/**
|
|
414
424
|
* Get quote details, including a callback function to post the order on-chain.
|
|
415
425
|
*
|
|
@@ -433,7 +443,9 @@ declare class BridgingSdk {
|
|
|
433
443
|
|
|
434
444
|
declare const RAW_PROVIDERS_FILES_PATH = "https://raw.githubusercontent.com/cowprotocol/cow-sdk/refs/heads/main/src/bridging/providers";
|
|
435
445
|
declare const DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION = 240000;
|
|
446
|
+
declare const DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION = 200000;
|
|
436
447
|
declare const COW_SHED_PROXY_CREATION_GAS = 360000;
|
|
448
|
+
declare const DEFAULT_EXTRA_GAS_PROXY_CREATION = 400000;
|
|
437
449
|
declare const HOOK_DAPP_BRIDGE_PROVIDER_PREFIX = "cow-sdk://bridging/providers";
|
|
438
450
|
|
|
439
451
|
interface GetCrossChainOrderParams {
|
|
@@ -709,13 +721,13 @@ declare class AcrossBridgeProvider implements BridgeProvider<AcrossQuoteResult>
|
|
|
709
721
|
constructor(options?: AcrossBridgeProviderOptions, _adapter?: AbstractProviderAdapter);
|
|
710
722
|
info: BridgeProviderInfo;
|
|
711
723
|
getNetworks(): Promise<ChainInfo[]>;
|
|
712
|
-
getBuyTokens(params: BuyTokensParams): Promise<
|
|
724
|
+
getBuyTokens(params: BuyTokensParams): Promise<GetProviderBuyTokens>;
|
|
713
725
|
getIntermediateTokens(request: QuoteBridgeRequest): Promise<TokenInfo[]>;
|
|
714
726
|
getQuote(request: QuoteBridgeRequest): Promise<AcrossQuoteResult>;
|
|
715
727
|
getUnsignedBridgeCall(request: QuoteBridgeRequest, quote: AcrossQuoteResult): Promise<EvmCall>;
|
|
716
728
|
getGasLimitEstimationForHook(request: QuoteBridgeRequest): Promise<number>;
|
|
717
729
|
getSignedHook(chainId: SupportedChainId, unsignedCall: EvmCall, bridgeHookNonce: string, deadline: bigint, hookGasLimit: number, signer?: SignerLike): Promise<BridgeHook>;
|
|
718
|
-
decodeBridgeHook(_hook:
|
|
730
|
+
decodeBridgeHook(_hook: cowAppDataLatestScheme.CoWHook): Promise<BridgeDeposit>;
|
|
719
731
|
getBridgingParams(chainId: ChainId, orderUid: string, txHash: string): Promise<{
|
|
720
732
|
params: BridgingDepositParams;
|
|
721
733
|
status: BridgeStatusResult;
|
|
@@ -727,7 +739,7 @@ declare class AcrossBridgeProvider implements BridgeProvider<AcrossQuoteResult>
|
|
|
727
739
|
private getSupportedTokensState;
|
|
728
740
|
}
|
|
729
741
|
|
|
730
|
-
type SupportedBridge = 'across' | 'cctp';
|
|
742
|
+
type SupportedBridge = 'across' | 'cctp' | 'gnosis-native-bridge';
|
|
731
743
|
interface BungeeQuoteAPIRequest {
|
|
732
744
|
userAddress: string;
|
|
733
745
|
originChainId: string;
|
|
@@ -834,7 +846,8 @@ interface BungeeQuoteAPIResponse {
|
|
|
834
846
|
}
|
|
835
847
|
declare enum BungeeBridge {
|
|
836
848
|
'Across' = "across",
|
|
837
|
-
'CircleCCTP' = "cctp"
|
|
849
|
+
'CircleCCTP' = "cctp",
|
|
850
|
+
'GnosisNative' = "gnosis-native-bridge"
|
|
838
851
|
}
|
|
839
852
|
interface BungeeQuote {
|
|
840
853
|
originChainId: number;
|
|
@@ -943,6 +956,7 @@ interface BungeeApiOptions {
|
|
|
943
956
|
eventsApiBaseUrl?: string;
|
|
944
957
|
acrossApiBaseUrl?: string;
|
|
945
958
|
includeBridges?: SupportedBridge[];
|
|
959
|
+
affiliate?: string;
|
|
946
960
|
}
|
|
947
961
|
interface IntermediateTokensParams {
|
|
948
962
|
fromChainId: SupportedChainId;
|
|
@@ -1015,7 +1029,7 @@ declare class BungeeBridgeProvider implements BridgeProvider<BungeeQuoteResult>
|
|
|
1015
1029
|
constructor(options: BungeeBridgeProviderOptions, _adapter?: AbstractProviderAdapter);
|
|
1016
1030
|
info: BridgeProviderInfo;
|
|
1017
1031
|
getNetworks(): Promise<ChainInfo[]>;
|
|
1018
|
-
getBuyTokens(params: BuyTokensParams): Promise<
|
|
1032
|
+
getBuyTokens(params: BuyTokensParams): Promise<GetProviderBuyTokens>;
|
|
1019
1033
|
getIntermediateTokens(request: QuoteBridgeRequest): Promise<TokenInfo[]>;
|
|
1020
1034
|
getQuote(request: QuoteBridgeRequest): Promise<BungeeQuoteResult>;
|
|
1021
1035
|
getUnsignedBridgeCall(request: QuoteBridgeRequest, quote: BungeeQuoteResult): Promise<EvmCall>;
|
|
@@ -1025,11 +1039,12 @@ declare class BungeeBridgeProvider implements BridgeProvider<BungeeQuoteResult>
|
|
|
1025
1039
|
params: BridgingDepositParams;
|
|
1026
1040
|
status: BridgeStatusResult;
|
|
1027
1041
|
} | null>;
|
|
1028
|
-
decodeBridgeHook(_hook:
|
|
1042
|
+
decodeBridgeHook(_hook: cowAppDataLatestScheme.CoWHook): Promise<BridgeDeposit>;
|
|
1029
1043
|
getExplorerUrl(bridgingId: string): string;
|
|
1030
1044
|
getStatus(_bridgingId: string): Promise<BridgeStatusResult>;
|
|
1031
1045
|
getCancelBridgingTx(_bridgingId: string): Promise<EvmCall>;
|
|
1032
1046
|
getRefundBridgingTx(_bridgingId: string): Promise<EvmCall>;
|
|
1047
|
+
private isExtraGasRequired;
|
|
1033
1048
|
}
|
|
1034
1049
|
|
|
1035
|
-
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_GAS_COST_FOR_HOOK_ESTIMATION, type GetOrderParams, HOOK_DAPP_BRIDGE_PROVIDER_PREFIX, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, RAW_PROVIDERS_FILES_PATH, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getCrossChainOrder, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isQuoteAndPost };
|
|
1050
|
+
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.js
CHANGED
|
@@ -29,6 +29,8 @@ __export(src_exports, {
|
|
|
29
29
|
BridgingSdk: () => BridgingSdk,
|
|
30
30
|
BungeeBridgeProvider: () => BungeeBridgeProvider,
|
|
31
31
|
COW_SHED_PROXY_CREATION_GAS: () => COW_SHED_PROXY_CREATION_GAS,
|
|
32
|
+
DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION: () => DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION,
|
|
33
|
+
DEFAULT_EXTRA_GAS_PROXY_CREATION: () => DEFAULT_EXTRA_GAS_PROXY_CREATION,
|
|
32
34
|
DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION: () => DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION,
|
|
33
35
|
HOOK_DAPP_BRIDGE_PROVIDER_PREFIX: () => HOOK_DAPP_BRIDGE_PROVIDER_PREFIX,
|
|
34
36
|
RAW_PROVIDERS_FILES_PATH: () => RAW_PROVIDERS_FILES_PATH,
|
|
@@ -146,7 +148,7 @@ async function getBridgeSignedHook(bridgeRequest, { provider, signer, hookGasLim
|
|
|
146
148
|
const adapter = (0, import_sdk_common2.getGlobalAdapter)();
|
|
147
149
|
const bridgingQuote = await provider.getQuote(bridgeRequest);
|
|
148
150
|
const unsignedBridgeCall = await provider.getUnsignedBridgeCall(bridgeRequest, bridgingQuote);
|
|
149
|
-
const deadline = BigInt(validToOverride
|
|
151
|
+
const deadline = BigInt(validToOverride ?? swapResult.orderToSign.validTo);
|
|
150
152
|
const bridgeHookNonce = adapter.utils.solidityKeccak256(
|
|
151
153
|
["bytes", "uint256"],
|
|
152
154
|
[unsignedBridgeCall.data, deadline]
|
|
@@ -170,7 +172,9 @@ async function getBridgeSignedHook(bridgeRequest, { provider, signer, hookGasLim
|
|
|
170
172
|
var import_sdk_config = require("@cowprotocol/sdk-config");
|
|
171
173
|
var RAW_PROVIDERS_FILES_PATH = `${import_sdk_config.RAW_FILES_PATH}/src/bridging/providers`;
|
|
172
174
|
var DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION = 24e4;
|
|
175
|
+
var DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION = 2e5;
|
|
173
176
|
var COW_SHED_PROXY_CREATION_GAS = 36e4;
|
|
177
|
+
var DEFAULT_EXTRA_GAS_PROXY_CREATION = 4e5;
|
|
174
178
|
var HOOK_DAPP_BRIDGE_PROVIDER_PREFIX = "cow-sdk://bridging/providers";
|
|
175
179
|
|
|
176
180
|
// src/BridgingSdk/getQuoteWithBridge.ts
|
|
@@ -468,8 +472,11 @@ var import_sdk_order_book2 = require("@cowprotocol/sdk-order-book");
|
|
|
468
472
|
var import_sdk_config2 = require("@cowprotocol/sdk-config");
|
|
469
473
|
var import_sdk_common4 = require("@cowprotocol/sdk-common");
|
|
470
474
|
var BridgingSdk = class {
|
|
471
|
-
constructor(options) {
|
|
475
|
+
constructor(options, adapter) {
|
|
472
476
|
this.options = options;
|
|
477
|
+
if (adapter) {
|
|
478
|
+
(0, import_sdk_common4.setGlobalAdapter)(adapter);
|
|
479
|
+
}
|
|
473
480
|
const { providers, ...restOptions } = options;
|
|
474
481
|
if (!providers || providers.length !== 1) {
|
|
475
482
|
throw new Error("Current implementation only supports a single bridge provider");
|
|
@@ -2779,14 +2786,20 @@ async function getDepositParams(chainId, orderId, txReceipt) {
|
|
|
2779
2786
|
|
|
2780
2787
|
// src/providers/utils/getGasLimitEstimationForHook.ts
|
|
2781
2788
|
var import_sdk_common10 = require("@cowprotocol/sdk-common");
|
|
2782
|
-
async function getGasLimitEstimationForHook(
|
|
2789
|
+
async function getGasLimitEstimationForHook({
|
|
2790
|
+
cowShedSdk,
|
|
2791
|
+
request,
|
|
2792
|
+
extraGas,
|
|
2793
|
+
extraGasProxyCreation
|
|
2794
|
+
}) {
|
|
2783
2795
|
const adapter = (0, import_sdk_common10.getGlobalAdapter)();
|
|
2784
2796
|
const proxyAddress = cowShedSdk.getCowShedAccount(request.sellTokenChainId, request.owner || request.account);
|
|
2785
2797
|
const proxyCode = await adapter.getCode(proxyAddress);
|
|
2786
2798
|
if (!proxyCode || proxyCode === "0x") {
|
|
2787
|
-
|
|
2799
|
+
const baseGas = DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION + COW_SHED_PROXY_CREATION_GAS;
|
|
2800
|
+
return baseGas + (extraGasProxyCreation && extraGasProxyCreation > 0 ? extraGasProxyCreation : 0);
|
|
2788
2801
|
}
|
|
2789
|
-
return DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION;
|
|
2802
|
+
return DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION + (extraGas && extraGas > 0 ? extraGas : 0);
|
|
2790
2803
|
}
|
|
2791
2804
|
|
|
2792
2805
|
// src/providers/across/AcrossBridgeProvider.ts
|
|
@@ -2819,7 +2832,12 @@ var AcrossBridgeProvider = class {
|
|
|
2819
2832
|
return ACROSS_SUPPORTED_NETWORKS;
|
|
2820
2833
|
}
|
|
2821
2834
|
async getBuyTokens(params) {
|
|
2822
|
-
|
|
2835
|
+
const tokens = Object.values((await this.getSupportedTokensState())[params.buyChainId] || {});
|
|
2836
|
+
const isRouteAvailable = tokens.length > 0;
|
|
2837
|
+
return {
|
|
2838
|
+
tokens,
|
|
2839
|
+
isRouteAvailable
|
|
2840
|
+
};
|
|
2823
2841
|
}
|
|
2824
2842
|
async getIntermediateTokens(request) {
|
|
2825
2843
|
if (request.kind !== import_sdk_order_book4.OrderKind.SELL) {
|
|
@@ -2856,7 +2874,10 @@ var AcrossBridgeProvider = class {
|
|
|
2856
2874
|
});
|
|
2857
2875
|
}
|
|
2858
2876
|
async getGasLimitEstimationForHook(request) {
|
|
2859
|
-
return getGasLimitEstimationForHook(
|
|
2877
|
+
return getGasLimitEstimationForHook({
|
|
2878
|
+
cowShedSdk: this.cowShedSdk,
|
|
2879
|
+
request
|
|
2880
|
+
});
|
|
2860
2881
|
}
|
|
2861
2882
|
async getSignedHook(chainId, unsignedCall, bridgeHookNonce, deadline, hookGasLimit, signer) {
|
|
2862
2883
|
const { signedMulticall, cowShedAccount, gasLimit } = await this.cowShedSdk.signCalls({
|
|
@@ -3006,13 +3027,42 @@ var BungeeTxDataBytesIndices = {
|
|
|
3006
3027
|
// 32 bytes = 64 chars for the amount
|
|
3007
3028
|
}
|
|
3008
3029
|
}
|
|
3030
|
+
},
|
|
3031
|
+
"gnosis-native-bridge": {
|
|
3032
|
+
// bridgeERC20To (amount is 5th param -> 8 + 4*32 = 136)
|
|
3033
|
+
["0x3bf5c228".toLowerCase()]: {
|
|
3034
|
+
inputAmount: {
|
|
3035
|
+
bytes_startIndex: 136,
|
|
3036
|
+
// first 136 bytes are the routeId, followed by the function selector
|
|
3037
|
+
bytes_length: 32,
|
|
3038
|
+
// first 32 bytes of the params are the amount
|
|
3039
|
+
bytesString_startIndex: 2 + 8 * 2,
|
|
3040
|
+
// first two characters are 0x and 8 bytes = 16 chars for the amount
|
|
3041
|
+
bytesString_length: 32 * 2
|
|
3042
|
+
// 32 bytes = 64 chars for the amount
|
|
3043
|
+
}
|
|
3044
|
+
},
|
|
3045
|
+
// bridgeNativeTo (amount is 4th param -> 8 + 3*32 = 104)
|
|
3046
|
+
["0xfcb23eb0".toLowerCase()]: {
|
|
3047
|
+
inputAmount: {
|
|
3048
|
+
bytes_startIndex: 104,
|
|
3049
|
+
// first 104 bytes are the routeId, followed by the function selector
|
|
3050
|
+
bytes_length: 32,
|
|
3051
|
+
// first 32 bytes of the params are the amount
|
|
3052
|
+
bytesString_startIndex: 2 + 8 * 2,
|
|
3053
|
+
// first two characters are 0x and 8 bytes = 16 chars for the amount
|
|
3054
|
+
bytesString_length: 32 * 2
|
|
3055
|
+
// 32 bytes = 64 chars for the amount
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3009
3058
|
}
|
|
3010
3059
|
};
|
|
3011
3060
|
|
|
3012
3061
|
// src/providers/bungee/types.ts
|
|
3013
3062
|
var BungeeBridgeNames = {
|
|
3014
3063
|
Across: "across" /* Across */,
|
|
3015
|
-
"Circle CCTP": "cctp" /* CircleCCTP
|
|
3064
|
+
"Circle CCTP": "cctp" /* CircleCCTP */,
|
|
3065
|
+
"Gnosis Native": "gnosis-native-bridge" /* GnosisNative */
|
|
3016
3066
|
};
|
|
3017
3067
|
|
|
3018
3068
|
// src/providers/bungee/util.ts
|
|
@@ -3381,11 +3431,12 @@ var BUNGEE_APPROVE_AND_BRIDGE_V1_ABI = [
|
|
|
3381
3431
|
|
|
3382
3432
|
// src/providers/bungee/BungeeApi.ts
|
|
3383
3433
|
var import_sdk_common12 = require("@cowprotocol/sdk-common");
|
|
3384
|
-
var
|
|
3385
|
-
var
|
|
3434
|
+
var BUNGEE_BASE_URL = "https://public-backend.bungee.exchange";
|
|
3435
|
+
var BUNGEE_API_URL = `${BUNGEE_BASE_URL}/api/v1/bungee`;
|
|
3436
|
+
var BUNGEE_MANUAL_API_URL = `${BUNGEE_BASE_URL}/api/v1/bungee-manual`;
|
|
3386
3437
|
var BUNGEE_EVENTS_API_URL = "https://microservices.socket.tech/loki";
|
|
3387
3438
|
var ACROSS_API_URL2 = "https://app.across.to/api";
|
|
3388
|
-
var SUPPORTED_BRIDGES = ["across", "cctp"];
|
|
3439
|
+
var SUPPORTED_BRIDGES = ["across", "cctp", "gnosis-native-bridge"];
|
|
3389
3440
|
var errorMessageMap = {
|
|
3390
3441
|
bungee: "Bungee Api Error",
|
|
3391
3442
|
events: "Bungee Events Api Error",
|
|
@@ -3638,8 +3689,12 @@ var BungeeApi = class {
|
|
|
3638
3689
|
};
|
|
3639
3690
|
const baseUrl = baseUrlMap[apiType];
|
|
3640
3691
|
const url = `${baseUrl}${path}?${new URLSearchParams(params).toString()}`;
|
|
3692
|
+
const headers = {};
|
|
3693
|
+
if (this.options.affiliate && !baseUrl.includes(BUNGEE_BASE_URL)) {
|
|
3694
|
+
headers["affiliate"] = this.options.affiliate;
|
|
3695
|
+
}
|
|
3641
3696
|
(0, import_sdk_common12.log)(`Fetching ${apiType} API: GET ${url}. Params: ${JSON.stringify(params)}`);
|
|
3642
|
-
const response = await fetch(url, { method: "GET" });
|
|
3697
|
+
const response = await fetch(url, { method: "GET", headers });
|
|
3643
3698
|
if (!response.ok) {
|
|
3644
3699
|
const errorBody = await response.json();
|
|
3645
3700
|
throw new BridgeProviderQuoteError("API_ERROR" /* API_ERROR */, { errorBody, type: errorMessageMap[apiType] });
|
|
@@ -3701,7 +3756,8 @@ function isValidBungeeEventsResponse(response) {
|
|
|
3701
3756
|
return false;
|
|
3702
3757
|
}
|
|
3703
3758
|
const e = event;
|
|
3704
|
-
return "identifier" in e && "bridgeName" in e && "fromChainId" in e && "isCowswapTrade" in e && "orderId" in e &&
|
|
3759
|
+
return "identifier" in e && "bridgeName" in e && "fromChainId" in e && "isCowswapTrade" in e && "orderId" in e && // 'recipient' in e &&
|
|
3760
|
+
"sender" in e && "srcTxStatus" in e && "destTxStatus" in e;
|
|
3705
3761
|
});
|
|
3706
3762
|
}
|
|
3707
3763
|
function isValidAcrossStatusResponse(response) {
|
|
@@ -3814,7 +3870,7 @@ var import_sdk_config8 = require("@cowprotocol/sdk-config");
|
|
|
3814
3870
|
var import_sdk_cow_shed2 = require("@cowprotocol/sdk-cow-shed");
|
|
3815
3871
|
var import_sdk_common14 = require("@cowprotocol/sdk-common");
|
|
3816
3872
|
var BUNGEE_HOOK_DAPP_ID = `${HOOK_DAPP_BRIDGE_PROVIDER_PREFIX2}/bungee`;
|
|
3817
|
-
var BUNGEE_SUPPORTED_NETWORKS = [import_sdk_config8.mainnet, import_sdk_config8.polygon, import_sdk_config8.arbitrumOne, import_sdk_config8.base, import_sdk_config8.optimism, import_sdk_config8.avalanche];
|
|
3873
|
+
var BUNGEE_SUPPORTED_NETWORKS = [import_sdk_config8.mainnet, import_sdk_config8.polygon, import_sdk_config8.arbitrumOne, import_sdk_config8.base, import_sdk_config8.optimism, import_sdk_config8.avalanche, import_sdk_config8.gnosisChain];
|
|
3818
3874
|
var SLIPPAGE_TOLERANCE_BPS2 = 0;
|
|
3819
3875
|
var BungeeBridgeProvider = class {
|
|
3820
3876
|
constructor(options, _adapter) {
|
|
@@ -3838,7 +3894,12 @@ var BungeeBridgeProvider = class {
|
|
|
3838
3894
|
return BUNGEE_SUPPORTED_NETWORKS;
|
|
3839
3895
|
}
|
|
3840
3896
|
async getBuyTokens(params) {
|
|
3841
|
-
|
|
3897
|
+
const tokens = await this.api.getBuyTokens(params);
|
|
3898
|
+
const isRouteAvailable = tokens.length > 0;
|
|
3899
|
+
return {
|
|
3900
|
+
tokens,
|
|
3901
|
+
isRouteAvailable
|
|
3902
|
+
};
|
|
3842
3903
|
}
|
|
3843
3904
|
async getIntermediateTokens(request) {
|
|
3844
3905
|
if (request.kind !== import_sdk_order_book6.OrderKind.SELL) {
|
|
@@ -3883,7 +3944,15 @@ var BungeeBridgeProvider = class {
|
|
|
3883
3944
|
});
|
|
3884
3945
|
}
|
|
3885
3946
|
async getGasLimitEstimationForHook(request) {
|
|
3886
|
-
|
|
3947
|
+
const isExtraGasRequired = this.isExtraGasRequired(request);
|
|
3948
|
+
const extraGas = isExtraGasRequired ? DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION : void 0;
|
|
3949
|
+
const extraGasProxyCreation = isExtraGasRequired ? DEFAULT_EXTRA_GAS_PROXY_CREATION : void 0;
|
|
3950
|
+
return getGasLimitEstimationForHook({
|
|
3951
|
+
cowShedSdk: this.cowShedSdk,
|
|
3952
|
+
request,
|
|
3953
|
+
extraGas,
|
|
3954
|
+
extraGasProxyCreation
|
|
3955
|
+
});
|
|
3887
3956
|
}
|
|
3888
3957
|
async getSignedHook(chainId, unsignedCall, bridgeHookNonce, deadline, hookGasLimit, signer) {
|
|
3889
3958
|
const { signedMulticall, cowShedAccount, gasLimit } = await this.cowShedSdk.signCalls({
|
|
@@ -3915,7 +3984,7 @@ var BungeeBridgeProvider = class {
|
|
|
3915
3984
|
}
|
|
3916
3985
|
async getBridgingParams(_chainId, orderId, _txHash) {
|
|
3917
3986
|
const events = await this.api.getEvents({ orderId });
|
|
3918
|
-
const event = events[0];
|
|
3987
|
+
const event = events?.[0];
|
|
3919
3988
|
if (!event)
|
|
3920
3989
|
return null;
|
|
3921
3990
|
const status = await getBridgingStatusFromEvents(events, (orderId2) => this.api.getAcrossStatus(orderId2));
|
|
@@ -3950,6 +4019,10 @@ var BungeeBridgeProvider = class {
|
|
|
3950
4019
|
async getRefundBridgingTx(_bridgingId) {
|
|
3951
4020
|
throw new Error("Not implemented");
|
|
3952
4021
|
}
|
|
4022
|
+
isExtraGasRequired(request) {
|
|
4023
|
+
const { sellTokenChainId, buyTokenChainId } = request;
|
|
4024
|
+
return sellTokenChainId === import_sdk_config8.SupportedChainId.MAINNET && buyTokenChainId === import_sdk_config8.SupportedChainId.GNOSIS_CHAIN;
|
|
4025
|
+
}
|
|
3953
4026
|
};
|
|
3954
4027
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3955
4028
|
0 && (module.exports = {
|
|
@@ -3962,6 +4035,8 @@ var BungeeBridgeProvider = class {
|
|
|
3962
4035
|
BridgingSdk,
|
|
3963
4036
|
BungeeBridgeProvider,
|
|
3964
4037
|
COW_SHED_PROXY_CREATION_GAS,
|
|
4038
|
+
DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION,
|
|
4039
|
+
DEFAULT_EXTRA_GAS_PROXY_CREATION,
|
|
3965
4040
|
DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION,
|
|
3966
4041
|
HOOK_DAPP_BRIDGE_PROVIDER_PREFIX,
|
|
3967
4042
|
RAW_PROVIDERS_FILES_PATH,
|
package/dist/index.mjs
CHANGED
|
@@ -106,7 +106,7 @@ async function getBridgeSignedHook(bridgeRequest, { provider, signer, hookGasLim
|
|
|
106
106
|
const adapter = getGlobalAdapter();
|
|
107
107
|
const bridgingQuote = await provider.getQuote(bridgeRequest);
|
|
108
108
|
const unsignedBridgeCall = await provider.getUnsignedBridgeCall(bridgeRequest, bridgingQuote);
|
|
109
|
-
const deadline = BigInt(validToOverride
|
|
109
|
+
const deadline = BigInt(validToOverride ?? swapResult.orderToSign.validTo);
|
|
110
110
|
const bridgeHookNonce = adapter.utils.solidityKeccak256(
|
|
111
111
|
["bytes", "uint256"],
|
|
112
112
|
[unsignedBridgeCall.data, deadline]
|
|
@@ -130,7 +130,9 @@ async function getBridgeSignedHook(bridgeRequest, { provider, signer, hookGasLim
|
|
|
130
130
|
import { RAW_FILES_PATH } from "@cowprotocol/sdk-config";
|
|
131
131
|
var RAW_PROVIDERS_FILES_PATH = `${RAW_FILES_PATH}/src/bridging/providers`;
|
|
132
132
|
var DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION = 24e4;
|
|
133
|
+
var DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION = 2e5;
|
|
133
134
|
var COW_SHED_PROXY_CREATION_GAS = 36e4;
|
|
135
|
+
var DEFAULT_EXTRA_GAS_PROXY_CREATION = 4e5;
|
|
134
136
|
var HOOK_DAPP_BRIDGE_PROVIDER_PREFIX = "cow-sdk://bridging/providers";
|
|
135
137
|
|
|
136
138
|
// src/BridgingSdk/getQuoteWithBridge.ts
|
|
@@ -426,10 +428,13 @@ async function getCrossChainOrder(params) {
|
|
|
426
428
|
import { TradingSdk } from "@cowprotocol/sdk-trading";
|
|
427
429
|
import { OrderBookApi } from "@cowprotocol/sdk-order-book";
|
|
428
430
|
import { ALL_SUPPORTED_CHAINS } from "@cowprotocol/sdk-config";
|
|
429
|
-
import { enableLogging } from "@cowprotocol/sdk-common";
|
|
431
|
+
import { enableLogging, setGlobalAdapter } from "@cowprotocol/sdk-common";
|
|
430
432
|
var BridgingSdk = class {
|
|
431
|
-
constructor(options) {
|
|
433
|
+
constructor(options, adapter) {
|
|
432
434
|
this.options = options;
|
|
435
|
+
if (adapter) {
|
|
436
|
+
setGlobalAdapter(adapter);
|
|
437
|
+
}
|
|
433
438
|
const { providers, ...restOptions } = options;
|
|
434
439
|
if (!providers || providers.length !== 1) {
|
|
435
440
|
throw new Error("Current implementation only supports a single bridge provider");
|
|
@@ -2739,18 +2744,24 @@ async function getDepositParams(chainId, orderId, txReceipt) {
|
|
|
2739
2744
|
|
|
2740
2745
|
// src/providers/utils/getGasLimitEstimationForHook.ts
|
|
2741
2746
|
import { getGlobalAdapter as getGlobalAdapter6 } from "@cowprotocol/sdk-common";
|
|
2742
|
-
async function getGasLimitEstimationForHook(
|
|
2747
|
+
async function getGasLimitEstimationForHook({
|
|
2748
|
+
cowShedSdk,
|
|
2749
|
+
request,
|
|
2750
|
+
extraGas,
|
|
2751
|
+
extraGasProxyCreation
|
|
2752
|
+
}) {
|
|
2743
2753
|
const adapter = getGlobalAdapter6();
|
|
2744
2754
|
const proxyAddress = cowShedSdk.getCowShedAccount(request.sellTokenChainId, request.owner || request.account);
|
|
2745
2755
|
const proxyCode = await adapter.getCode(proxyAddress);
|
|
2746
2756
|
if (!proxyCode || proxyCode === "0x") {
|
|
2747
|
-
|
|
2757
|
+
const baseGas = DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION + COW_SHED_PROXY_CREATION_GAS;
|
|
2758
|
+
return baseGas + (extraGasProxyCreation && extraGasProxyCreation > 0 ? extraGasProxyCreation : 0);
|
|
2748
2759
|
}
|
|
2749
|
-
return DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION;
|
|
2760
|
+
return DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION + (extraGas && extraGas > 0 ? extraGas : 0);
|
|
2750
2761
|
}
|
|
2751
2762
|
|
|
2752
2763
|
// src/providers/across/AcrossBridgeProvider.ts
|
|
2753
|
-
import { getGlobalAdapter as getGlobalAdapter7, setGlobalAdapter } from "@cowprotocol/sdk-common";
|
|
2764
|
+
import { getGlobalAdapter as getGlobalAdapter7, setGlobalAdapter as setGlobalAdapter2 } from "@cowprotocol/sdk-common";
|
|
2754
2765
|
import {
|
|
2755
2766
|
arbitrumOne,
|
|
2756
2767
|
base,
|
|
@@ -2770,7 +2781,7 @@ var AcrossBridgeProvider = class {
|
|
|
2770
2781
|
constructor(options = {}, _adapter) {
|
|
2771
2782
|
const adapter = _adapter || options.cowShedOptions?.adapter;
|
|
2772
2783
|
if (adapter) {
|
|
2773
|
-
|
|
2784
|
+
setGlobalAdapter2(adapter);
|
|
2774
2785
|
}
|
|
2775
2786
|
this.api = new AcrossApi(options.apiOptions);
|
|
2776
2787
|
this.cowShedSdk = new CowShedSdk(adapter, options.cowShedOptions?.factoryOptions);
|
|
@@ -2785,7 +2796,12 @@ var AcrossBridgeProvider = class {
|
|
|
2785
2796
|
return ACROSS_SUPPORTED_NETWORKS;
|
|
2786
2797
|
}
|
|
2787
2798
|
async getBuyTokens(params) {
|
|
2788
|
-
|
|
2799
|
+
const tokens = Object.values((await this.getSupportedTokensState())[params.buyChainId] || {});
|
|
2800
|
+
const isRouteAvailable = tokens.length > 0;
|
|
2801
|
+
return {
|
|
2802
|
+
tokens,
|
|
2803
|
+
isRouteAvailable
|
|
2804
|
+
};
|
|
2789
2805
|
}
|
|
2790
2806
|
async getIntermediateTokens(request) {
|
|
2791
2807
|
if (request.kind !== OrderKind3.SELL) {
|
|
@@ -2822,7 +2838,10 @@ var AcrossBridgeProvider = class {
|
|
|
2822
2838
|
});
|
|
2823
2839
|
}
|
|
2824
2840
|
async getGasLimitEstimationForHook(request) {
|
|
2825
|
-
return getGasLimitEstimationForHook(
|
|
2841
|
+
return getGasLimitEstimationForHook({
|
|
2842
|
+
cowShedSdk: this.cowShedSdk,
|
|
2843
|
+
request
|
|
2844
|
+
});
|
|
2826
2845
|
}
|
|
2827
2846
|
async getSignedHook(chainId, unsignedCall, bridgeHookNonce, deadline, hookGasLimit, signer) {
|
|
2828
2847
|
const { signedMulticall, cowShedAccount, gasLimit } = await this.cowShedSdk.signCalls({
|
|
@@ -2972,13 +2991,42 @@ var BungeeTxDataBytesIndices = {
|
|
|
2972
2991
|
// 32 bytes = 64 chars for the amount
|
|
2973
2992
|
}
|
|
2974
2993
|
}
|
|
2994
|
+
},
|
|
2995
|
+
"gnosis-native-bridge": {
|
|
2996
|
+
// bridgeERC20To (amount is 5th param -> 8 + 4*32 = 136)
|
|
2997
|
+
["0x3bf5c228".toLowerCase()]: {
|
|
2998
|
+
inputAmount: {
|
|
2999
|
+
bytes_startIndex: 136,
|
|
3000
|
+
// first 136 bytes are the routeId, followed by the function selector
|
|
3001
|
+
bytes_length: 32,
|
|
3002
|
+
// first 32 bytes of the params are the amount
|
|
3003
|
+
bytesString_startIndex: 2 + 8 * 2,
|
|
3004
|
+
// first two characters are 0x and 8 bytes = 16 chars for the amount
|
|
3005
|
+
bytesString_length: 32 * 2
|
|
3006
|
+
// 32 bytes = 64 chars for the amount
|
|
3007
|
+
}
|
|
3008
|
+
},
|
|
3009
|
+
// bridgeNativeTo (amount is 4th param -> 8 + 3*32 = 104)
|
|
3010
|
+
["0xfcb23eb0".toLowerCase()]: {
|
|
3011
|
+
inputAmount: {
|
|
3012
|
+
bytes_startIndex: 104,
|
|
3013
|
+
// first 104 bytes are the routeId, followed by the function selector
|
|
3014
|
+
bytes_length: 32,
|
|
3015
|
+
// first 32 bytes of the params are the amount
|
|
3016
|
+
bytesString_startIndex: 2 + 8 * 2,
|
|
3017
|
+
// first two characters are 0x and 8 bytes = 16 chars for the amount
|
|
3018
|
+
bytesString_length: 32 * 2
|
|
3019
|
+
// 32 bytes = 64 chars for the amount
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
2975
3022
|
}
|
|
2976
3023
|
};
|
|
2977
3024
|
|
|
2978
3025
|
// src/providers/bungee/types.ts
|
|
2979
3026
|
var BungeeBridgeNames = {
|
|
2980
3027
|
Across: "across" /* Across */,
|
|
2981
|
-
"Circle CCTP": "cctp" /* CircleCCTP
|
|
3028
|
+
"Circle CCTP": "cctp" /* CircleCCTP */,
|
|
3029
|
+
"Gnosis Native": "gnosis-native-bridge" /* GnosisNative */
|
|
2982
3030
|
};
|
|
2983
3031
|
|
|
2984
3032
|
// src/providers/bungee/util.ts
|
|
@@ -3347,11 +3395,12 @@ var BUNGEE_APPROVE_AND_BRIDGE_V1_ABI = [
|
|
|
3347
3395
|
|
|
3348
3396
|
// src/providers/bungee/BungeeApi.ts
|
|
3349
3397
|
import { getGlobalAdapter as getGlobalAdapter8, log as log5 } from "@cowprotocol/sdk-common";
|
|
3350
|
-
var
|
|
3351
|
-
var
|
|
3398
|
+
var BUNGEE_BASE_URL = "https://public-backend.bungee.exchange";
|
|
3399
|
+
var BUNGEE_API_URL = `${BUNGEE_BASE_URL}/api/v1/bungee`;
|
|
3400
|
+
var BUNGEE_MANUAL_API_URL = `${BUNGEE_BASE_URL}/api/v1/bungee-manual`;
|
|
3352
3401
|
var BUNGEE_EVENTS_API_URL = "https://microservices.socket.tech/loki";
|
|
3353
3402
|
var ACROSS_API_URL2 = "https://app.across.to/api";
|
|
3354
|
-
var SUPPORTED_BRIDGES = ["across", "cctp"];
|
|
3403
|
+
var SUPPORTED_BRIDGES = ["across", "cctp", "gnosis-native-bridge"];
|
|
3355
3404
|
var errorMessageMap = {
|
|
3356
3405
|
bungee: "Bungee Api Error",
|
|
3357
3406
|
events: "Bungee Events Api Error",
|
|
@@ -3604,8 +3653,12 @@ var BungeeApi = class {
|
|
|
3604
3653
|
};
|
|
3605
3654
|
const baseUrl = baseUrlMap[apiType];
|
|
3606
3655
|
const url = `${baseUrl}${path}?${new URLSearchParams(params).toString()}`;
|
|
3656
|
+
const headers = {};
|
|
3657
|
+
if (this.options.affiliate && !baseUrl.includes(BUNGEE_BASE_URL)) {
|
|
3658
|
+
headers["affiliate"] = this.options.affiliate;
|
|
3659
|
+
}
|
|
3607
3660
|
log5(`Fetching ${apiType} API: GET ${url}. Params: ${JSON.stringify(params)}`);
|
|
3608
|
-
const response = await fetch(url, { method: "GET" });
|
|
3661
|
+
const response = await fetch(url, { method: "GET", headers });
|
|
3609
3662
|
if (!response.ok) {
|
|
3610
3663
|
const errorBody = await response.json();
|
|
3611
3664
|
throw new BridgeProviderQuoteError("API_ERROR" /* API_ERROR */, { errorBody, type: errorMessageMap[apiType] });
|
|
@@ -3667,7 +3720,8 @@ function isValidBungeeEventsResponse(response) {
|
|
|
3667
3720
|
return false;
|
|
3668
3721
|
}
|
|
3669
3722
|
const e = event;
|
|
3670
|
-
return "identifier" in e && "bridgeName" in e && "fromChainId" in e && "isCowswapTrade" in e && "orderId" in e &&
|
|
3723
|
+
return "identifier" in e && "bridgeName" in e && "fromChainId" in e && "isCowswapTrade" in e && "orderId" in e && // 'recipient' in e &&
|
|
3724
|
+
"sender" in e && "srcTxStatus" in e && "destTxStatus" in e;
|
|
3671
3725
|
});
|
|
3672
3726
|
}
|
|
3673
3727
|
function isValidAcrossStatusResponse(response) {
|
|
@@ -3780,21 +3834,23 @@ import {
|
|
|
3780
3834
|
arbitrumOne as arbitrumOne2,
|
|
3781
3835
|
avalanche,
|
|
3782
3836
|
base as base2,
|
|
3837
|
+
gnosisChain,
|
|
3783
3838
|
mainnet as mainnet2,
|
|
3784
3839
|
optimism as optimism2,
|
|
3785
|
-
polygon as polygon2
|
|
3840
|
+
polygon as polygon2,
|
|
3841
|
+
SupportedChainId as SupportedChainId6
|
|
3786
3842
|
} from "@cowprotocol/sdk-config";
|
|
3787
3843
|
import { CowShedSdk as CowShedSdk2 } from "@cowprotocol/sdk-cow-shed";
|
|
3788
|
-
import { setGlobalAdapter as
|
|
3844
|
+
import { setGlobalAdapter as setGlobalAdapter3 } from "@cowprotocol/sdk-common";
|
|
3789
3845
|
var BUNGEE_HOOK_DAPP_ID = `${HOOK_DAPP_BRIDGE_PROVIDER_PREFIX2}/bungee`;
|
|
3790
|
-
var BUNGEE_SUPPORTED_NETWORKS = [mainnet2, polygon2, arbitrumOne2, base2, optimism2, avalanche];
|
|
3846
|
+
var BUNGEE_SUPPORTED_NETWORKS = [mainnet2, polygon2, arbitrumOne2, base2, optimism2, avalanche, gnosisChain];
|
|
3791
3847
|
var SLIPPAGE_TOLERANCE_BPS2 = 0;
|
|
3792
3848
|
var BungeeBridgeProvider = class {
|
|
3793
3849
|
constructor(options, _adapter) {
|
|
3794
3850
|
this.options = options;
|
|
3795
3851
|
const adapter = _adapter || options.cowShedOptions?.adapter;
|
|
3796
3852
|
if (adapter) {
|
|
3797
|
-
|
|
3853
|
+
setGlobalAdapter3(adapter);
|
|
3798
3854
|
}
|
|
3799
3855
|
this.api = new BungeeApi(options.apiOptions);
|
|
3800
3856
|
this.cowShedSdk = new CowShedSdk2(adapter, options.cowShedOptions?.factoryOptions);
|
|
@@ -3811,7 +3867,12 @@ var BungeeBridgeProvider = class {
|
|
|
3811
3867
|
return BUNGEE_SUPPORTED_NETWORKS;
|
|
3812
3868
|
}
|
|
3813
3869
|
async getBuyTokens(params) {
|
|
3814
|
-
|
|
3870
|
+
const tokens = await this.api.getBuyTokens(params);
|
|
3871
|
+
const isRouteAvailable = tokens.length > 0;
|
|
3872
|
+
return {
|
|
3873
|
+
tokens,
|
|
3874
|
+
isRouteAvailable
|
|
3875
|
+
};
|
|
3815
3876
|
}
|
|
3816
3877
|
async getIntermediateTokens(request) {
|
|
3817
3878
|
if (request.kind !== OrderKind5.SELL) {
|
|
@@ -3856,7 +3917,15 @@ var BungeeBridgeProvider = class {
|
|
|
3856
3917
|
});
|
|
3857
3918
|
}
|
|
3858
3919
|
async getGasLimitEstimationForHook(request) {
|
|
3859
|
-
|
|
3920
|
+
const isExtraGasRequired = this.isExtraGasRequired(request);
|
|
3921
|
+
const extraGas = isExtraGasRequired ? DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION : void 0;
|
|
3922
|
+
const extraGasProxyCreation = isExtraGasRequired ? DEFAULT_EXTRA_GAS_PROXY_CREATION : void 0;
|
|
3923
|
+
return getGasLimitEstimationForHook({
|
|
3924
|
+
cowShedSdk: this.cowShedSdk,
|
|
3925
|
+
request,
|
|
3926
|
+
extraGas,
|
|
3927
|
+
extraGasProxyCreation
|
|
3928
|
+
});
|
|
3860
3929
|
}
|
|
3861
3930
|
async getSignedHook(chainId, unsignedCall, bridgeHookNonce, deadline, hookGasLimit, signer) {
|
|
3862
3931
|
const { signedMulticall, cowShedAccount, gasLimit } = await this.cowShedSdk.signCalls({
|
|
@@ -3888,7 +3957,7 @@ var BungeeBridgeProvider = class {
|
|
|
3888
3957
|
}
|
|
3889
3958
|
async getBridgingParams(_chainId, orderId, _txHash) {
|
|
3890
3959
|
const events = await this.api.getEvents({ orderId });
|
|
3891
|
-
const event = events[0];
|
|
3960
|
+
const event = events?.[0];
|
|
3892
3961
|
if (!event)
|
|
3893
3962
|
return null;
|
|
3894
3963
|
const status = await getBridgingStatusFromEvents(events, (orderId2) => this.api.getAcrossStatus(orderId2));
|
|
@@ -3923,6 +3992,10 @@ var BungeeBridgeProvider = class {
|
|
|
3923
3992
|
async getRefundBridgingTx(_bridgingId) {
|
|
3924
3993
|
throw new Error("Not implemented");
|
|
3925
3994
|
}
|
|
3995
|
+
isExtraGasRequired(request) {
|
|
3996
|
+
const { sellTokenChainId, buyTokenChainId } = request;
|
|
3997
|
+
return sellTokenChainId === SupportedChainId6.MAINNET && buyTokenChainId === SupportedChainId6.GNOSIS_CHAIN;
|
|
3998
|
+
}
|
|
3926
3999
|
};
|
|
3927
4000
|
export {
|
|
3928
4001
|
AcrossBridgeProvider,
|
|
@@ -3934,6 +4007,8 @@ export {
|
|
|
3934
4007
|
BridgingSdk,
|
|
3935
4008
|
BungeeBridgeProvider,
|
|
3936
4009
|
COW_SHED_PROXY_CREATION_GAS,
|
|
4010
|
+
DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION,
|
|
4011
|
+
DEFAULT_EXTRA_GAS_PROXY_CREATION,
|
|
3937
4012
|
DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION,
|
|
3938
4013
|
HOOK_DAPP_BRIDGE_PROVIDER_PREFIX,
|
|
3939
4014
|
RAW_PROVIDERS_FILES_PATH,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-bridging",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-beta.0",
|
|
4
4
|
"description": "Bridging for CoW Protocol",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"test": "jest",
|
|
21
21
|
"test:coverage": "jest --coverage --json --outputFile=jest.results.json && npx coveralls < ./coverage/lcov.info",
|
|
22
22
|
"test:coverage:html": "jest --silent=false --coverage --coverageReporters html",
|
|
23
|
+
"test:bungeeGnosisBridge": "yarn test --testPathPattern=BungeeGnosisBridge",
|
|
23
24
|
"typecheck": "tsc --noEmit",
|
|
24
|
-
"publish": "npm publish --access public",
|
|
25
25
|
"prepublishOnly": "npm run build"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|