@cowprotocol/sdk-bridging 0.11.0 → 0.12.1
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 +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +60 -35
- package/dist/index.mjs +60 -36
- package/package.json +12 -11
package/dist/index.d.mts
CHANGED
|
@@ -428,7 +428,7 @@ interface BestQuoteProviderContext extends MultiQuoteContext {
|
|
|
428
428
|
bestResult: {
|
|
429
429
|
current: MultiQuoteResult | null;
|
|
430
430
|
};
|
|
431
|
-
|
|
431
|
+
bestError: {
|
|
432
432
|
current: MultiQuoteResult | null;
|
|
433
433
|
};
|
|
434
434
|
}
|
|
@@ -443,8 +443,10 @@ declare enum BridgeQuoteErrors {
|
|
|
443
443
|
QUOTE_ERROR = "QUOTE_ERROR",
|
|
444
444
|
NO_ROUTES = "NO_ROUTES",
|
|
445
445
|
INVALID_BRIDGE = "INVALID_BRIDGE",
|
|
446
|
-
QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS = "QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS"
|
|
446
|
+
QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS = "QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS",
|
|
447
|
+
SELL_AMOUNT_TOO_SMALL = "SELL_AMOUNT_TOO_SMALL"
|
|
447
448
|
}
|
|
449
|
+
declare const BridgeQuoteErrorPriorities: Record<BridgeQuoteErrors, number>;
|
|
448
450
|
declare class BridgeProviderQuoteError extends Error {
|
|
449
451
|
readonly context?: unknown | undefined;
|
|
450
452
|
constructor(message: BridgeQuoteErrors, context?: unknown | undefined);
|
|
@@ -1294,4 +1296,4 @@ declare class NearIntentsBridgeProvider implements ReceiverAccountBridgeProvider
|
|
|
1294
1296
|
} | null>;
|
|
1295
1297
|
}
|
|
1296
1298
|
|
|
1297
|
-
export { AcrossBridgeProvider, type AcrossBridgeProviderOptions, type AcrossQuoteResult, type BestQuoteProgressCallback, type BestQuoteProviderContext, type BridgeCallDetails, type BridgeCosts, type BridgeDeposit, type BridgeHook, BridgeOrderParsingError, type BridgeProvider, BridgeProviderError, type BridgeProviderInfo, BridgeProviderQuoteError, type BridgeProviderType, type BridgeQuoteAmountsAndCosts, type BridgeQuoteAndPost, BridgeQuoteErrors, type BridgeQuoteResult, type BridgeQuoteResults, BridgeStatus, type BridgeStatusResult, type BridgingDepositParams, BridgingSdk, BungeeBridgeProvider, type BungeeBridgeProviderOptions, type BungeeQuoteResult, type BuyTokensParams, COW_SHED_PROXY_CREATION_GAS, type CrossChainOrder, type CrossChainQuoteAndPost, DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION, DEFAULT_EXTRA_GAS_PROXY_CREATION, DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION, type DefaultBridgeProvider, type GetProviderBuyTokens, HOOK_DAPP_BRIDGE_PROVIDER_PREFIX, type HookBridgeProvider, type MultiQuoteOptions, type MultiQuoteProgressCallback, type MultiQuoteRequest, type MultiQuoteResult, NearIntentsBridgeProvider, type NearIntentsBridgeProviderOptions, type NearIntentsQuoteResult, type ProviderQuoteContext, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, RAW_PROVIDERS_FILES_PATH, type ReceiverAccountBridgeProvider, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getCrossChainOrder, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isHookBridgeProvider, isQuoteAndPost, isReceiverAccountBridgeProvider };
|
|
1299
|
+
export { AcrossBridgeProvider, type AcrossBridgeProviderOptions, type AcrossQuoteResult, type BestQuoteProgressCallback, type BestQuoteProviderContext, type BridgeCallDetails, type BridgeCosts, type BridgeDeposit, type BridgeHook, BridgeOrderParsingError, type BridgeProvider, BridgeProviderError, type BridgeProviderInfo, BridgeProviderQuoteError, type BridgeProviderType, type BridgeQuoteAmountsAndCosts, type BridgeQuoteAndPost, BridgeQuoteErrorPriorities, BridgeQuoteErrors, type BridgeQuoteResult, type BridgeQuoteResults, BridgeStatus, type BridgeStatusResult, type BridgingDepositParams, BridgingSdk, BungeeBridgeProvider, type BungeeBridgeProviderOptions, type BungeeQuoteResult, type BuyTokensParams, COW_SHED_PROXY_CREATION_GAS, type CrossChainOrder, type CrossChainQuoteAndPost, DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION, DEFAULT_EXTRA_GAS_PROXY_CREATION, DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION, type DefaultBridgeProvider, type GetProviderBuyTokens, HOOK_DAPP_BRIDGE_PROVIDER_PREFIX, type HookBridgeProvider, type MultiQuoteOptions, type MultiQuoteProgressCallback, type MultiQuoteRequest, type MultiQuoteResult, NearIntentsBridgeProvider, type NearIntentsBridgeProviderOptions, type NearIntentsQuoteResult, type ProviderQuoteContext, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, RAW_PROVIDERS_FILES_PATH, type ReceiverAccountBridgeProvider, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getCrossChainOrder, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isHookBridgeProvider, isQuoteAndPost, isReceiverAccountBridgeProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -428,7 +428,7 @@ interface BestQuoteProviderContext extends MultiQuoteContext {
|
|
|
428
428
|
bestResult: {
|
|
429
429
|
current: MultiQuoteResult | null;
|
|
430
430
|
};
|
|
431
|
-
|
|
431
|
+
bestError: {
|
|
432
432
|
current: MultiQuoteResult | null;
|
|
433
433
|
};
|
|
434
434
|
}
|
|
@@ -443,8 +443,10 @@ declare enum BridgeQuoteErrors {
|
|
|
443
443
|
QUOTE_ERROR = "QUOTE_ERROR",
|
|
444
444
|
NO_ROUTES = "NO_ROUTES",
|
|
445
445
|
INVALID_BRIDGE = "INVALID_BRIDGE",
|
|
446
|
-
QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS = "QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS"
|
|
446
|
+
QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS = "QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS",
|
|
447
|
+
SELL_AMOUNT_TOO_SMALL = "SELL_AMOUNT_TOO_SMALL"
|
|
447
448
|
}
|
|
449
|
+
declare const BridgeQuoteErrorPriorities: Record<BridgeQuoteErrors, number>;
|
|
448
450
|
declare class BridgeProviderQuoteError extends Error {
|
|
449
451
|
readonly context?: unknown | undefined;
|
|
450
452
|
constructor(message: BridgeQuoteErrors, context?: unknown | undefined);
|
|
@@ -1294,4 +1296,4 @@ declare class NearIntentsBridgeProvider implements ReceiverAccountBridgeProvider
|
|
|
1294
1296
|
} | null>;
|
|
1295
1297
|
}
|
|
1296
1298
|
|
|
1297
|
-
export { AcrossBridgeProvider, type AcrossBridgeProviderOptions, type AcrossQuoteResult, type BestQuoteProgressCallback, type BestQuoteProviderContext, type BridgeCallDetails, type BridgeCosts, type BridgeDeposit, type BridgeHook, BridgeOrderParsingError, type BridgeProvider, BridgeProviderError, type BridgeProviderInfo, BridgeProviderQuoteError, type BridgeProviderType, type BridgeQuoteAmountsAndCosts, type BridgeQuoteAndPost, BridgeQuoteErrors, type BridgeQuoteResult, type BridgeQuoteResults, BridgeStatus, type BridgeStatusResult, type BridgingDepositParams, BridgingSdk, BungeeBridgeProvider, type BungeeBridgeProviderOptions, type BungeeQuoteResult, type BuyTokensParams, COW_SHED_PROXY_CREATION_GAS, type CrossChainOrder, type CrossChainQuoteAndPost, DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION, DEFAULT_EXTRA_GAS_PROXY_CREATION, DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION, type DefaultBridgeProvider, type GetProviderBuyTokens, HOOK_DAPP_BRIDGE_PROVIDER_PREFIX, type HookBridgeProvider, type MultiQuoteOptions, type MultiQuoteProgressCallback, type MultiQuoteRequest, type MultiQuoteResult, NearIntentsBridgeProvider, type NearIntentsBridgeProviderOptions, type NearIntentsQuoteResult, type ProviderQuoteContext, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, RAW_PROVIDERS_FILES_PATH, type ReceiverAccountBridgeProvider, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getCrossChainOrder, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isHookBridgeProvider, isQuoteAndPost, isReceiverAccountBridgeProvider };
|
|
1299
|
+
export { AcrossBridgeProvider, type AcrossBridgeProviderOptions, type AcrossQuoteResult, type BestQuoteProgressCallback, type BestQuoteProviderContext, type BridgeCallDetails, type BridgeCosts, type BridgeDeposit, type BridgeHook, BridgeOrderParsingError, type BridgeProvider, BridgeProviderError, type BridgeProviderInfo, BridgeProviderQuoteError, type BridgeProviderType, type BridgeQuoteAmountsAndCosts, type BridgeQuoteAndPost, BridgeQuoteErrorPriorities, BridgeQuoteErrors, type BridgeQuoteResult, type BridgeQuoteResults, BridgeStatus, type BridgeStatusResult, type BridgingDepositParams, BridgingSdk, BungeeBridgeProvider, type BungeeBridgeProviderOptions, type BungeeQuoteResult, type BuyTokensParams, COW_SHED_PROXY_CREATION_GAS, type CrossChainOrder, type CrossChainQuoteAndPost, DEFAULT_EXTRA_GAS_FOR_HOOK_ESTIMATION, DEFAULT_EXTRA_GAS_PROXY_CREATION, DEFAULT_GAS_COST_FOR_HOOK_ESTIMATION, type DefaultBridgeProvider, type GetProviderBuyTokens, HOOK_DAPP_BRIDGE_PROVIDER_PREFIX, type HookBridgeProvider, type MultiQuoteOptions, type MultiQuoteProgressCallback, type MultiQuoteRequest, type MultiQuoteResult, NearIntentsBridgeProvider, type NearIntentsBridgeProviderOptions, type NearIntentsQuoteResult, type ProviderQuoteContext, type QuoteBridgeRequest, type QuoteBridgeRequestWithoutAmount, RAW_PROVIDERS_FILES_PATH, type ReceiverAccountBridgeProvider, assertIsBridgeQuoteAndPost, assertIsQuoteAndPost, getCrossChainOrder, getPostHooks, isAppDoc, isBridgeQuoteAndPost, isHookBridgeProvider, isQuoteAndPost, isReceiverAccountBridgeProvider };
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
BridgeOrderParsingError: () => BridgeOrderParsingError,
|
|
35
35
|
BridgeProviderError: () => BridgeProviderError,
|
|
36
36
|
BridgeProviderQuoteError: () => BridgeProviderQuoteError,
|
|
37
|
+
BridgeQuoteErrorPriorities: () => BridgeQuoteErrorPriorities,
|
|
37
38
|
BridgeQuoteErrors: () => BridgeQuoteErrors,
|
|
38
39
|
BridgeStatus: () => BridgeStatus,
|
|
39
40
|
BridgingSdk: () => BridgingSdk,
|
|
@@ -78,8 +79,21 @@ var BridgeQuoteErrors = /* @__PURE__ */ ((BridgeQuoteErrors2) => {
|
|
|
78
79
|
BridgeQuoteErrors2["NO_ROUTES"] = "NO_ROUTES";
|
|
79
80
|
BridgeQuoteErrors2["INVALID_BRIDGE"] = "INVALID_BRIDGE";
|
|
80
81
|
BridgeQuoteErrors2["QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS"] = "QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS";
|
|
82
|
+
BridgeQuoteErrors2["SELL_AMOUNT_TOO_SMALL"] = "SELL_AMOUNT_TOO_SMALL";
|
|
81
83
|
return BridgeQuoteErrors2;
|
|
82
84
|
})(BridgeQuoteErrors || {});
|
|
85
|
+
var BridgeQuoteErrorPriorities = {
|
|
86
|
+
["SELL_AMOUNT_TOO_SMALL" /* SELL_AMOUNT_TOO_SMALL */]: 10,
|
|
87
|
+
["ONLY_SELL_ORDER_SUPPORTED" /* ONLY_SELL_ORDER_SUPPORTED */]: 9,
|
|
88
|
+
["NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */]: 1,
|
|
89
|
+
["API_ERROR" /* API_ERROR */]: 1,
|
|
90
|
+
["INVALID_API_JSON_RESPONSE" /* INVALID_API_JSON_RESPONSE */]: 1,
|
|
91
|
+
["TX_BUILD_ERROR" /* TX_BUILD_ERROR */]: 1,
|
|
92
|
+
["QUOTE_ERROR" /* QUOTE_ERROR */]: 1,
|
|
93
|
+
["NO_ROUTES" /* NO_ROUTES */]: 1,
|
|
94
|
+
["INVALID_BRIDGE" /* INVALID_BRIDGE */]: 1,
|
|
95
|
+
["QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS" /* QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS */]: 1
|
|
96
|
+
};
|
|
83
97
|
var BridgeProviderQuoteError = class extends Error {
|
|
84
98
|
constructor(message, context) {
|
|
85
99
|
super(message);
|
|
@@ -949,6 +963,25 @@ function resolveProvidersToQuery(providerDappIds, providers) {
|
|
|
949
963
|
return provider;
|
|
950
964
|
});
|
|
951
965
|
}
|
|
966
|
+
function getErrorPriority(error) {
|
|
967
|
+
if (!error)
|
|
968
|
+
return 0;
|
|
969
|
+
if (error instanceof BridgeProviderQuoteError) {
|
|
970
|
+
return BridgeQuoteErrorPriorities[error.message] ?? 0;
|
|
971
|
+
}
|
|
972
|
+
return 0;
|
|
973
|
+
}
|
|
974
|
+
function isBetterError(error1, error2) {
|
|
975
|
+
if (!error2 || !error2.error) {
|
|
976
|
+
return !!error1?.error;
|
|
977
|
+
}
|
|
978
|
+
if (!error1?.error) {
|
|
979
|
+
return false;
|
|
980
|
+
}
|
|
981
|
+
const priority1 = getErrorPriority(error1.error);
|
|
982
|
+
const priority2 = getErrorPriority(error2.error);
|
|
983
|
+
return priority1 > priority2;
|
|
984
|
+
}
|
|
952
985
|
|
|
953
986
|
// src/BridgingSdk/strategies/MultiQuoteStrategy.ts
|
|
954
987
|
var DEFAULT_TOTAL_TIMEOUT_MS = 4e4;
|
|
@@ -1055,7 +1088,7 @@ var BestQuoteStrategy = class extends BaseBestQuoteStrategy {
|
|
|
1055
1088
|
providerTimeout = DEFAULT_PROVIDER_TIMEOUT_MS2
|
|
1056
1089
|
} = options || {};
|
|
1057
1090
|
const bestResult = { current: null };
|
|
1058
|
-
const
|
|
1091
|
+
const bestError = { current: null };
|
|
1059
1092
|
const promises = [];
|
|
1060
1093
|
for (const provider of providersToQuery) {
|
|
1061
1094
|
const context = {
|
|
@@ -1065,16 +1098,16 @@ var BestQuoteStrategy = class extends BaseBestQuoteStrategy {
|
|
|
1065
1098
|
providerTimeout,
|
|
1066
1099
|
onQuoteResult,
|
|
1067
1100
|
bestResult,
|
|
1068
|
-
|
|
1101
|
+
bestError
|
|
1069
1102
|
};
|
|
1070
1103
|
const promise = this.createBestQuoteProviderPromise(context, tradingSdk);
|
|
1071
1104
|
promises.push(promise);
|
|
1072
1105
|
}
|
|
1073
1106
|
await executeProviderQuotes(promises, totalTimeout, providers);
|
|
1074
|
-
return bestResult.current ||
|
|
1107
|
+
return bestResult.current || bestError.current;
|
|
1075
1108
|
}
|
|
1076
1109
|
createBestQuoteProviderPromise(context, tradingSdk) {
|
|
1077
|
-
const { provider, quoteBridgeRequest, advancedSettings, providerTimeout, onQuoteResult, bestResult,
|
|
1110
|
+
const { provider, quoteBridgeRequest, advancedSettings, providerTimeout, onQuoteResult, bestResult, bestError } = context;
|
|
1078
1111
|
return (async () => {
|
|
1079
1112
|
try {
|
|
1080
1113
|
const baseParams = {
|
|
@@ -1107,8 +1140,8 @@ var BestQuoteStrategy = class extends BaseBestQuoteStrategy {
|
|
|
1107
1140
|
quote: null,
|
|
1108
1141
|
error: error instanceof Error ? error : new BridgeProviderError(String(error), {})
|
|
1109
1142
|
};
|
|
1110
|
-
if (
|
|
1111
|
-
|
|
1143
|
+
if (isBetterError(errorResult, bestError.current)) {
|
|
1144
|
+
bestError.current = errorResult;
|
|
1112
1145
|
}
|
|
1113
1146
|
}
|
|
1114
1147
|
})();
|
|
@@ -3771,7 +3804,7 @@ var HOOK_DAPP_BRIDGE_PROVIDER_PREFIX2 = "cow-sdk://bridging/providers";
|
|
|
3771
3804
|
var BungeeTxDataBytesIndices = {
|
|
3772
3805
|
across: {
|
|
3773
3806
|
// bridgeERC20To
|
|
3774
|
-
["
|
|
3807
|
+
["0xcc54d224".toLowerCase()]: {
|
|
3775
3808
|
inputAmount: {
|
|
3776
3809
|
bytes_startIndex: 8,
|
|
3777
3810
|
// first 8 bytes are the routeId, followed by the function selector
|
|
@@ -3781,20 +3814,10 @@ var BungeeTxDataBytesIndices = {
|
|
|
3781
3814
|
// first two characters are 0x and 8 bytes = 16 chars for the amount
|
|
3782
3815
|
bytesString_length: 32 * 2
|
|
3783
3816
|
// 32 bytes = 64 chars for the amount
|
|
3784
|
-
},
|
|
3785
|
-
outputAmount: {
|
|
3786
|
-
bytes_startIndex: 488,
|
|
3787
|
-
// outputAmount is part of the AcrossBridgeData struct in SocketGateway AcrossV3 impl
|
|
3788
|
-
bytes_length: 32,
|
|
3789
|
-
// 32 bytes of amount
|
|
3790
|
-
bytesString_startIndex: 2 + 488 * 2,
|
|
3791
|
-
// first two characters are 0x and 484 bytes = 968 chars for the amount
|
|
3792
|
-
bytesString_length: 32 * 2
|
|
3793
|
-
// 32 bytes = 64 chars for the amount
|
|
3794
3817
|
}
|
|
3795
3818
|
},
|
|
3796
3819
|
// bridgeNativeTo
|
|
3797
|
-
["
|
|
3820
|
+
["0xa3b8bfba".toLowerCase()]: {
|
|
3798
3821
|
inputAmount: {
|
|
3799
3822
|
bytes_startIndex: 8,
|
|
3800
3823
|
// first 8 bytes are the routeId, followed by the function selector
|
|
@@ -3804,16 +3827,6 @@ var BungeeTxDataBytesIndices = {
|
|
|
3804
3827
|
// first two characters are 0x and 8 bytes = 16 chars for the amount
|
|
3805
3828
|
bytesString_length: 32 * 2
|
|
3806
3829
|
// 32 bytes = 64 chars for the amount
|
|
3807
|
-
},
|
|
3808
|
-
outputAmount: {
|
|
3809
|
-
bytes_startIndex: 392,
|
|
3810
|
-
// outputAmount is part of the AcrossBridgeData struct in SocketGateway AcrossV3 impl
|
|
3811
|
-
bytes_length: 32,
|
|
3812
|
-
// 32 bytes of amount
|
|
3813
|
-
bytesString_startIndex: 2 + 392 * 2,
|
|
3814
|
-
// first two characters are 0x and 484 bytes = 968 chars for the amount
|
|
3815
|
-
bytesString_length: 32 * 2
|
|
3816
|
-
// 32 bytes = 64 chars for the amount
|
|
3817
3830
|
}
|
|
3818
3831
|
}
|
|
3819
3832
|
},
|
|
@@ -4687,13 +4700,9 @@ async function createBungeeDepositCall(params) {
|
|
|
4687
4700
|
throw new Error(`createBungeeDepositCall() no params for function [${functionSelector}]`);
|
|
4688
4701
|
}
|
|
4689
4702
|
const inputAmountStartIndex = functionParams.inputAmount.bytes_startIndex;
|
|
4690
|
-
|
|
4691
|
-
|
|
4703
|
+
const modifyOutputAmount = false;
|
|
4704
|
+
const outputAmountStartIndex = 0;
|
|
4692
4705
|
const nativeTokenExtraFee = 0n;
|
|
4693
|
-
if (bridge === "across" /* Across */) {
|
|
4694
|
-
modifyOutputAmount = true;
|
|
4695
|
-
outputAmountStartIndex = functionParams.outputAmount.bytes_startIndex;
|
|
4696
|
-
}
|
|
4697
4706
|
const modifyCalldataParams = adapter.utils.encodeAbi(
|
|
4698
4707
|
["uint256", "bool", "uint256"],
|
|
4699
4708
|
[inputAmountStartIndex, modifyOutputAmount, outputAmountStartIndex]
|
|
@@ -4949,7 +4958,22 @@ var NearIntentsApi = class {
|
|
|
4949
4958
|
return this.cachedTokens;
|
|
4950
4959
|
}
|
|
4951
4960
|
async getQuote(request) {
|
|
4952
|
-
|
|
4961
|
+
try {
|
|
4962
|
+
return await import_one_click_sdk_typescript.OneClickService.getQuote(request);
|
|
4963
|
+
} catch (error) {
|
|
4964
|
+
if (error instanceof import_one_click_sdk_typescript.ApiError) {
|
|
4965
|
+
const message = error.body?.message;
|
|
4966
|
+
if (message && typeof message === "string" && message.toLowerCase().includes("amount is too low")) {
|
|
4967
|
+
const minAmountMatch = message.match(/try at least (\d+)/);
|
|
4968
|
+
const minAmount = minAmountMatch ? minAmountMatch[1] : void 0;
|
|
4969
|
+
throw new BridgeProviderQuoteError("SELL_AMOUNT_TOO_SMALL" /* SELL_AMOUNT_TOO_SMALL */, {
|
|
4970
|
+
originalMessage: message,
|
|
4971
|
+
minAmount
|
|
4972
|
+
});
|
|
4973
|
+
}
|
|
4974
|
+
}
|
|
4975
|
+
throw error;
|
|
4976
|
+
}
|
|
4953
4977
|
}
|
|
4954
4978
|
async getStatus(depositAddress) {
|
|
4955
4979
|
return await import_one_click_sdk_typescript.OneClickService.getExecutionStatus(depositAddress);
|
|
@@ -5345,6 +5369,7 @@ var NearIntentsBridgeProvider = class {
|
|
|
5345
5369
|
BridgeOrderParsingError,
|
|
5346
5370
|
BridgeProviderError,
|
|
5347
5371
|
BridgeProviderQuoteError,
|
|
5372
|
+
BridgeQuoteErrorPriorities,
|
|
5348
5373
|
BridgeQuoteErrors,
|
|
5349
5374
|
BridgeStatus,
|
|
5350
5375
|
BridgingSdk,
|
package/dist/index.mjs
CHANGED
|
@@ -19,8 +19,21 @@ var BridgeQuoteErrors = /* @__PURE__ */ ((BridgeQuoteErrors2) => {
|
|
|
19
19
|
BridgeQuoteErrors2["NO_ROUTES"] = "NO_ROUTES";
|
|
20
20
|
BridgeQuoteErrors2["INVALID_BRIDGE"] = "INVALID_BRIDGE";
|
|
21
21
|
BridgeQuoteErrors2["QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS"] = "QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS";
|
|
22
|
+
BridgeQuoteErrors2["SELL_AMOUNT_TOO_SMALL"] = "SELL_AMOUNT_TOO_SMALL";
|
|
22
23
|
return BridgeQuoteErrors2;
|
|
23
24
|
})(BridgeQuoteErrors || {});
|
|
25
|
+
var BridgeQuoteErrorPriorities = {
|
|
26
|
+
["SELL_AMOUNT_TOO_SMALL" /* SELL_AMOUNT_TOO_SMALL */]: 10,
|
|
27
|
+
["ONLY_SELL_ORDER_SUPPORTED" /* ONLY_SELL_ORDER_SUPPORTED */]: 9,
|
|
28
|
+
["NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */]: 1,
|
|
29
|
+
["API_ERROR" /* API_ERROR */]: 1,
|
|
30
|
+
["INVALID_API_JSON_RESPONSE" /* INVALID_API_JSON_RESPONSE */]: 1,
|
|
31
|
+
["TX_BUILD_ERROR" /* TX_BUILD_ERROR */]: 1,
|
|
32
|
+
["QUOTE_ERROR" /* QUOTE_ERROR */]: 1,
|
|
33
|
+
["NO_ROUTES" /* NO_ROUTES */]: 1,
|
|
34
|
+
["INVALID_BRIDGE" /* INVALID_BRIDGE */]: 1,
|
|
35
|
+
["QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS" /* QUOTE_DOES_NOT_MATCH_DEPOSIT_ADDRESS */]: 1
|
|
36
|
+
};
|
|
24
37
|
var BridgeProviderQuoteError = class extends Error {
|
|
25
38
|
constructor(message, context) {
|
|
26
39
|
super(message);
|
|
@@ -894,6 +907,25 @@ function resolveProvidersToQuery(providerDappIds, providers) {
|
|
|
894
907
|
return provider;
|
|
895
908
|
});
|
|
896
909
|
}
|
|
910
|
+
function getErrorPriority(error) {
|
|
911
|
+
if (!error)
|
|
912
|
+
return 0;
|
|
913
|
+
if (error instanceof BridgeProviderQuoteError) {
|
|
914
|
+
return BridgeQuoteErrorPriorities[error.message] ?? 0;
|
|
915
|
+
}
|
|
916
|
+
return 0;
|
|
917
|
+
}
|
|
918
|
+
function isBetterError(error1, error2) {
|
|
919
|
+
if (!error2 || !error2.error) {
|
|
920
|
+
return !!error1?.error;
|
|
921
|
+
}
|
|
922
|
+
if (!error1?.error) {
|
|
923
|
+
return false;
|
|
924
|
+
}
|
|
925
|
+
const priority1 = getErrorPriority(error1.error);
|
|
926
|
+
const priority2 = getErrorPriority(error2.error);
|
|
927
|
+
return priority1 > priority2;
|
|
928
|
+
}
|
|
897
929
|
|
|
898
930
|
// src/BridgingSdk/strategies/MultiQuoteStrategy.ts
|
|
899
931
|
var DEFAULT_TOTAL_TIMEOUT_MS = 4e4;
|
|
@@ -1000,7 +1032,7 @@ var BestQuoteStrategy = class extends BaseBestQuoteStrategy {
|
|
|
1000
1032
|
providerTimeout = DEFAULT_PROVIDER_TIMEOUT_MS2
|
|
1001
1033
|
} = options || {};
|
|
1002
1034
|
const bestResult = { current: null };
|
|
1003
|
-
const
|
|
1035
|
+
const bestError = { current: null };
|
|
1004
1036
|
const promises = [];
|
|
1005
1037
|
for (const provider of providersToQuery) {
|
|
1006
1038
|
const context = {
|
|
@@ -1010,16 +1042,16 @@ var BestQuoteStrategy = class extends BaseBestQuoteStrategy {
|
|
|
1010
1042
|
providerTimeout,
|
|
1011
1043
|
onQuoteResult,
|
|
1012
1044
|
bestResult,
|
|
1013
|
-
|
|
1045
|
+
bestError
|
|
1014
1046
|
};
|
|
1015
1047
|
const promise = this.createBestQuoteProviderPromise(context, tradingSdk);
|
|
1016
1048
|
promises.push(promise);
|
|
1017
1049
|
}
|
|
1018
1050
|
await executeProviderQuotes(promises, totalTimeout, providers);
|
|
1019
|
-
return bestResult.current ||
|
|
1051
|
+
return bestResult.current || bestError.current;
|
|
1020
1052
|
}
|
|
1021
1053
|
createBestQuoteProviderPromise(context, tradingSdk) {
|
|
1022
|
-
const { provider, quoteBridgeRequest, advancedSettings, providerTimeout, onQuoteResult, bestResult,
|
|
1054
|
+
const { provider, quoteBridgeRequest, advancedSettings, providerTimeout, onQuoteResult, bestResult, bestError } = context;
|
|
1023
1055
|
return (async () => {
|
|
1024
1056
|
try {
|
|
1025
1057
|
const baseParams = {
|
|
@@ -1052,8 +1084,8 @@ var BestQuoteStrategy = class extends BaseBestQuoteStrategy {
|
|
|
1052
1084
|
quote: null,
|
|
1053
1085
|
error: error instanceof Error ? error : new BridgeProviderError(String(error), {})
|
|
1054
1086
|
};
|
|
1055
|
-
if (
|
|
1056
|
-
|
|
1087
|
+
if (isBetterError(errorResult, bestError.current)) {
|
|
1088
|
+
bestError.current = errorResult;
|
|
1057
1089
|
}
|
|
1058
1090
|
}
|
|
1059
1091
|
})();
|
|
@@ -3722,7 +3754,7 @@ var HOOK_DAPP_BRIDGE_PROVIDER_PREFIX2 = "cow-sdk://bridging/providers";
|
|
|
3722
3754
|
var BungeeTxDataBytesIndices = {
|
|
3723
3755
|
across: {
|
|
3724
3756
|
// bridgeERC20To
|
|
3725
|
-
["
|
|
3757
|
+
["0xcc54d224".toLowerCase()]: {
|
|
3726
3758
|
inputAmount: {
|
|
3727
3759
|
bytes_startIndex: 8,
|
|
3728
3760
|
// first 8 bytes are the routeId, followed by the function selector
|
|
@@ -3732,20 +3764,10 @@ var BungeeTxDataBytesIndices = {
|
|
|
3732
3764
|
// first two characters are 0x and 8 bytes = 16 chars for the amount
|
|
3733
3765
|
bytesString_length: 32 * 2
|
|
3734
3766
|
// 32 bytes = 64 chars for the amount
|
|
3735
|
-
},
|
|
3736
|
-
outputAmount: {
|
|
3737
|
-
bytes_startIndex: 488,
|
|
3738
|
-
// outputAmount is part of the AcrossBridgeData struct in SocketGateway AcrossV3 impl
|
|
3739
|
-
bytes_length: 32,
|
|
3740
|
-
// 32 bytes of amount
|
|
3741
|
-
bytesString_startIndex: 2 + 488 * 2,
|
|
3742
|
-
// first two characters are 0x and 484 bytes = 968 chars for the amount
|
|
3743
|
-
bytesString_length: 32 * 2
|
|
3744
|
-
// 32 bytes = 64 chars for the amount
|
|
3745
3767
|
}
|
|
3746
3768
|
},
|
|
3747
3769
|
// bridgeNativeTo
|
|
3748
|
-
["
|
|
3770
|
+
["0xa3b8bfba".toLowerCase()]: {
|
|
3749
3771
|
inputAmount: {
|
|
3750
3772
|
bytes_startIndex: 8,
|
|
3751
3773
|
// first 8 bytes are the routeId, followed by the function selector
|
|
@@ -3755,16 +3777,6 @@ var BungeeTxDataBytesIndices = {
|
|
|
3755
3777
|
// first two characters are 0x and 8 bytes = 16 chars for the amount
|
|
3756
3778
|
bytesString_length: 32 * 2
|
|
3757
3779
|
// 32 bytes = 64 chars for the amount
|
|
3758
|
-
},
|
|
3759
|
-
outputAmount: {
|
|
3760
|
-
bytes_startIndex: 392,
|
|
3761
|
-
// outputAmount is part of the AcrossBridgeData struct in SocketGateway AcrossV3 impl
|
|
3762
|
-
bytes_length: 32,
|
|
3763
|
-
// 32 bytes of amount
|
|
3764
|
-
bytesString_startIndex: 2 + 392 * 2,
|
|
3765
|
-
// first two characters are 0x and 484 bytes = 968 chars for the amount
|
|
3766
|
-
bytesString_length: 32 * 2
|
|
3767
|
-
// 32 bytes = 64 chars for the amount
|
|
3768
3780
|
}
|
|
3769
3781
|
}
|
|
3770
3782
|
},
|
|
@@ -4638,13 +4650,9 @@ async function createBungeeDepositCall(params) {
|
|
|
4638
4650
|
throw new Error(`createBungeeDepositCall() no params for function [${functionSelector}]`);
|
|
4639
4651
|
}
|
|
4640
4652
|
const inputAmountStartIndex = functionParams.inputAmount.bytes_startIndex;
|
|
4641
|
-
|
|
4642
|
-
|
|
4653
|
+
const modifyOutputAmount = false;
|
|
4654
|
+
const outputAmountStartIndex = 0;
|
|
4643
4655
|
const nativeTokenExtraFee = 0n;
|
|
4644
|
-
if (bridge === "across" /* Across */) {
|
|
4645
|
-
modifyOutputAmount = true;
|
|
4646
|
-
outputAmountStartIndex = functionParams.outputAmount.bytes_startIndex;
|
|
4647
|
-
}
|
|
4648
4656
|
const modifyCalldataParams = adapter.utils.encodeAbi(
|
|
4649
4657
|
["uint256", "bool", "uint256"],
|
|
4650
4658
|
[inputAmountStartIndex, modifyOutputAmount, outputAmountStartIndex]
|
|
@@ -4898,7 +4906,7 @@ import { OrderKind as OrderKind6 } from "@cowprotocol/sdk-order-book";
|
|
|
4898
4906
|
import { QuoteRequest } from "@defuse-protocol/one-click-sdk-typescript";
|
|
4899
4907
|
|
|
4900
4908
|
// src/providers/near-intents/NearIntentsApi.ts
|
|
4901
|
-
import { OneClickService, OpenAPI } from "@defuse-protocol/one-click-sdk-typescript";
|
|
4909
|
+
import { ApiError, OneClickService, OpenAPI } from "@defuse-protocol/one-click-sdk-typescript";
|
|
4902
4910
|
var NearIntentsApi = class {
|
|
4903
4911
|
cachedTokens = [];
|
|
4904
4912
|
async getTokens() {
|
|
@@ -4909,7 +4917,22 @@ var NearIntentsApi = class {
|
|
|
4909
4917
|
return this.cachedTokens;
|
|
4910
4918
|
}
|
|
4911
4919
|
async getQuote(request) {
|
|
4912
|
-
|
|
4920
|
+
try {
|
|
4921
|
+
return await OneClickService.getQuote(request);
|
|
4922
|
+
} catch (error) {
|
|
4923
|
+
if (error instanceof ApiError) {
|
|
4924
|
+
const message = error.body?.message;
|
|
4925
|
+
if (message && typeof message === "string" && message.toLowerCase().includes("amount is too low")) {
|
|
4926
|
+
const minAmountMatch = message.match(/try at least (\d+)/);
|
|
4927
|
+
const minAmount = minAmountMatch ? minAmountMatch[1] : void 0;
|
|
4928
|
+
throw new BridgeProviderQuoteError("SELL_AMOUNT_TOO_SMALL" /* SELL_AMOUNT_TOO_SMALL */, {
|
|
4929
|
+
originalMessage: message,
|
|
4930
|
+
minAmount
|
|
4931
|
+
});
|
|
4932
|
+
}
|
|
4933
|
+
}
|
|
4934
|
+
throw error;
|
|
4935
|
+
}
|
|
4913
4936
|
}
|
|
4914
4937
|
async getStatus(depositAddress) {
|
|
4915
4938
|
return await OneClickService.getExecutionStatus(depositAddress);
|
|
@@ -5304,6 +5327,7 @@ export {
|
|
|
5304
5327
|
BridgeOrderParsingError,
|
|
5305
5328
|
BridgeProviderError,
|
|
5306
5329
|
BridgeProviderQuoteError,
|
|
5330
|
+
BridgeQuoteErrorPriorities,
|
|
5307
5331
|
BridgeQuoteErrors,
|
|
5308
5332
|
BridgeStatus,
|
|
5309
5333
|
BridgingSdk,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-bridging",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Bridging for CoW Protocol",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@defuse-protocol/one-click-sdk-typescript": "0.1.1-0.2",
|
|
18
18
|
"json-stable-stringify": "^1.3.0",
|
|
19
|
-
"@cowprotocol/sdk-app-data": "4.3.5",
|
|
20
19
|
"@cowprotocol/sdk-common": "0.4.0",
|
|
21
|
-
"@cowprotocol/sdk-contracts-ts": "0.8.
|
|
22
|
-
"@cowprotocol/sdk-
|
|
23
|
-
"@cowprotocol/sdk-order-book": "0.4.
|
|
24
|
-
"@cowprotocol/sdk-
|
|
25
|
-
"@cowprotocol/sdk-
|
|
26
|
-
"@cowprotocol/sdk-
|
|
20
|
+
"@cowprotocol/sdk-contracts-ts": "0.8.1",
|
|
21
|
+
"@cowprotocol/sdk-cow-shed": "0.2.8",
|
|
22
|
+
"@cowprotocol/sdk-order-book": "0.4.4",
|
|
23
|
+
"@cowprotocol/sdk-trading": "0.7.1",
|
|
24
|
+
"@cowprotocol/sdk-weiroll": "0.1.11",
|
|
25
|
+
"@cowprotocol/sdk-config": "0.6.2",
|
|
26
|
+
"@cowprotocol/sdk-app-data": "4.3.6"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/jest": "^29.4.0",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"tsup": "^7.2.0",
|
|
39
39
|
"typescript": "^5.2.2",
|
|
40
40
|
"viem": "^2.28.4",
|
|
41
|
-
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
42
41
|
"@cowprotocol/sdk-ethers-v5-adapter": "0.3.0",
|
|
42
|
+
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
43
43
|
"@cowprotocol/sdk-ethers-v6-adapter": "0.3.0",
|
|
44
|
-
"@cowprotocol/sdk-order-signing": "0.1.
|
|
44
|
+
"@cowprotocol/sdk-order-signing": "0.1.21",
|
|
45
45
|
"@cowprotocol/sdk-viem-adapter": "0.3.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
"test": "jest",
|
|
52
52
|
"test:coverage": "jest --coverage --json --outputFile=jest.results.json && npx coveralls < ./coverage/lcov.info",
|
|
53
53
|
"test:coverage:html": "jest --silent=false --coverage --coverageReporters html",
|
|
54
|
-
"test:bungeeGnosisBridge": "
|
|
54
|
+
"test:bungeeGnosisBridge": "jest --testPathPattern=BungeeGnosisBridge",
|
|
55
|
+
"test:bungeeAcrossBridge": "jest --testPathPattern=BungeeAcrossBridge",
|
|
55
56
|
"typecheck": "tsc --noEmit"
|
|
56
57
|
}
|
|
57
58
|
}
|