@cowprotocol/sdk-bridging 1.4.1 → 1.5.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.js CHANGED
@@ -383,7 +383,7 @@ function isCorrelatedToken(tokenAddress, correlatedTokens) {
383
383
  }
384
384
 
385
385
  // src/BridgingSdk/determineIntermediateToken.ts
386
- async function determineIntermediateToken(sourceChainId, sourceTokenAddress, intermediateTokens, getCorrelatedTokens) {
386
+ async function determineIntermediateToken(sourceChainId, sourceTokenAddress, intermediateTokens, getCorrelatedTokens, allowIntermediateEqSellToken) {
387
387
  const firstToken = intermediateTokens[0];
388
388
  if (intermediateTokens.length === 0 || !firstToken) {
389
389
  throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens });
@@ -394,7 +394,8 @@ async function determineIntermediateToken(sourceChainId, sourceTokenAddress, int
394
394
  const correlatedTokens = await resolveCorrelatedTokens(sourceChainId, getCorrelatedTokens);
395
395
  const sellTokenLike = { chainId: sourceChainId, address: sourceTokenAddress };
396
396
  const isSellNativeOrWrapped = (0, import_sdk_common3.isNativeToken)(sellTokenLike) || (0, import_sdk_common3.isWrappedNativeToken)(sellTokenLike);
397
- const tokensWithPriority = intermediateTokens.map((token) => {
397
+ const filteredTokens = allowIntermediateEqSellToken ? intermediateTokens : intermediateTokens.filter((token) => !(0, import_sdk_common3.areAddressesEqual)(token.address, sourceTokenAddress));
398
+ const tokensWithPriority = filteredTokens.map((token) => {
398
399
  const isNativeOrWrapped = (0, import_sdk_common3.isNativeToken)(token) || (0, import_sdk_common3.isWrappedNativeToken)(token);
399
400
  if ((0, import_sdk_common3.areAddressesEqual)(token.address, sourceTokenAddress)) {
400
401
  if (!(isSellNativeOrWrapped && isNativeOrWrapped)) {
@@ -416,11 +417,11 @@ async function determineIntermediateToken(sourceChainId, sourceTokenAddress, int
416
417
  if (a.priority !== b.priority) {
417
418
  return b.priority - a.priority;
418
419
  }
419
- return intermediateTokens.indexOf(a.token) - intermediateTokens.indexOf(b.token);
420
+ return filteredTokens.indexOf(a.token) - filteredTokens.indexOf(b.token);
420
421
  });
421
422
  const result = tokensWithPriority[0]?.token;
422
423
  if (!result) {
423
- throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens });
424
+ throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens: filteredTokens });
424
425
  }
425
426
  return result;
426
427
  }
@@ -445,7 +446,7 @@ async function getIntermediateSwapResult({
445
446
  params,
446
447
  getBridgeHook
447
448
  }) {
448
- const { swapAndBridgeRequest, advancedSettings, tradingSdk } = params;
449
+ const { swapAndBridgeRequest, advancedSettings, tradingSdk, allowIntermediateEqSellToken } = params;
449
450
  const {
450
451
  kind,
451
452
  sellTokenChainId,
@@ -469,7 +470,8 @@ async function getIntermediateSwapResult({
469
470
  sellTokenChainId,
470
471
  sellTokenAddress,
471
472
  intermediateTokens,
472
- params.advancedSettings?.getCorrelatedTokens
473
+ params.advancedSettings?.getCorrelatedTokens,
474
+ allowIntermediateEqSellToken
473
475
  );
474
476
  (0, import_sdk_common4.log)(`Using ${intermediateToken?.name ?? intermediateToken?.address} as intermediate tokens`);
475
477
  const bridgeRequestWithoutAmount = {
@@ -885,7 +887,8 @@ var SingleQuoteStrategy = class extends BaseSingleQuoteStrategy {
885
887
  swapAndBridgeRequest: quoteBridgeRequest,
886
888
  advancedSettings,
887
889
  tradingSdk,
888
- quoteSigner: advancedSettings?.quoteSigner
890
+ quoteSigner: advancedSettings?.quoteSigner,
891
+ allowIntermediateEqSellToken: advancedSettings?.allowIntermediateEqSellToken
889
892
  };
890
893
  const request2 = this.intermediateTokensCache ? {
891
894
  ...baseParams,
@@ -1021,7 +1024,8 @@ async function fetchMultiQuote(context, tradingSdk, intermediateTokensCache) {
1021
1024
  swapAndBridgeRequest: quoteBridgeRequest,
1022
1025
  advancedSettings,
1023
1026
  tradingSdk,
1024
- quoteSigner: advancedSettings?.quoteSigner
1027
+ quoteSigner: advancedSettings?.quoteSigner,
1028
+ allowIntermediateEqSellToken: advancedSettings?.allowIntermediateEqSellToken
1025
1029
  };
1026
1030
  const request = intermediateTokensCache ? {
1027
1031
  ...baseParams,
package/dist/index.mjs CHANGED
@@ -326,7 +326,7 @@ function isCorrelatedToken(tokenAddress, correlatedTokens) {
326
326
  }
327
327
 
328
328
  // src/BridgingSdk/determineIntermediateToken.ts
329
- async function determineIntermediateToken(sourceChainId, sourceTokenAddress, intermediateTokens, getCorrelatedTokens) {
329
+ async function determineIntermediateToken(sourceChainId, sourceTokenAddress, intermediateTokens, getCorrelatedTokens, allowIntermediateEqSellToken) {
330
330
  const firstToken = intermediateTokens[0];
331
331
  if (intermediateTokens.length === 0 || !firstToken) {
332
332
  throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens });
@@ -337,7 +337,8 @@ async function determineIntermediateToken(sourceChainId, sourceTokenAddress, int
337
337
  const correlatedTokens = await resolveCorrelatedTokens(sourceChainId, getCorrelatedTokens);
338
338
  const sellTokenLike = { chainId: sourceChainId, address: sourceTokenAddress };
339
339
  const isSellNativeOrWrapped = isNativeToken(sellTokenLike) || isWrappedNativeToken(sellTokenLike);
340
- const tokensWithPriority = intermediateTokens.map((token) => {
340
+ const filteredTokens = allowIntermediateEqSellToken ? intermediateTokens : intermediateTokens.filter((token) => !areAddressesEqual(token.address, sourceTokenAddress));
341
+ const tokensWithPriority = filteredTokens.map((token) => {
341
342
  const isNativeOrWrapped = isNativeToken(token) || isWrappedNativeToken(token);
342
343
  if (areAddressesEqual(token.address, sourceTokenAddress)) {
343
344
  if (!(isSellNativeOrWrapped && isNativeOrWrapped)) {
@@ -359,11 +360,11 @@ async function determineIntermediateToken(sourceChainId, sourceTokenAddress, int
359
360
  if (a.priority !== b.priority) {
360
361
  return b.priority - a.priority;
361
362
  }
362
- return intermediateTokens.indexOf(a.token) - intermediateTokens.indexOf(b.token);
363
+ return filteredTokens.indexOf(a.token) - filteredTokens.indexOf(b.token);
363
364
  });
364
365
  const result = tokensWithPriority[0]?.token;
365
366
  if (!result) {
366
- throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens });
367
+ throw new BridgeProviderQuoteError("NO_INTERMEDIATE_TOKENS" /* NO_INTERMEDIATE_TOKENS */, { intermediateTokens: filteredTokens });
367
368
  }
368
369
  return result;
369
370
  }
@@ -388,7 +389,7 @@ async function getIntermediateSwapResult({
388
389
  params,
389
390
  getBridgeHook
390
391
  }) {
391
- const { swapAndBridgeRequest, advancedSettings, tradingSdk } = params;
392
+ const { swapAndBridgeRequest, advancedSettings, tradingSdk, allowIntermediateEqSellToken } = params;
392
393
  const {
393
394
  kind,
394
395
  sellTokenChainId,
@@ -412,7 +413,8 @@ async function getIntermediateSwapResult({
412
413
  sellTokenChainId,
413
414
  sellTokenAddress,
414
415
  intermediateTokens,
415
- params.advancedSettings?.getCorrelatedTokens
416
+ params.advancedSettings?.getCorrelatedTokens,
417
+ allowIntermediateEqSellToken
416
418
  );
417
419
  log2(`Using ${intermediateToken?.name ?? intermediateToken?.address} as intermediate tokens`);
418
420
  const bridgeRequestWithoutAmount = {
@@ -828,7 +830,8 @@ var SingleQuoteStrategy = class extends BaseSingleQuoteStrategy {
828
830
  swapAndBridgeRequest: quoteBridgeRequest,
829
831
  advancedSettings,
830
832
  tradingSdk,
831
- quoteSigner: advancedSettings?.quoteSigner
833
+ quoteSigner: advancedSettings?.quoteSigner,
834
+ allowIntermediateEqSellToken: advancedSettings?.allowIntermediateEqSellToken
832
835
  };
833
836
  const request2 = this.intermediateTokensCache ? {
834
837
  ...baseParams,
@@ -964,7 +967,8 @@ async function fetchMultiQuote(context, tradingSdk, intermediateTokensCache) {
964
967
  swapAndBridgeRequest: quoteBridgeRequest,
965
968
  advancedSettings,
966
969
  tradingSdk,
967
- quoteSigner: advancedSettings?.quoteSigner
970
+ quoteSigner: advancedSettings?.quoteSigner,
971
+ allowIntermediateEqSellToken: advancedSettings?.allowIntermediateEqSellToken
968
972
  };
969
973
  const request = intermediateTokensCache ? {
970
974
  ...baseParams,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/sdk-bridging",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
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.5.1",
20
19
  "@cowprotocol/sdk-common": "0.5.0",
20
+ "@cowprotocol/sdk-app-data": "4.5.1",
21
21
  "@cowprotocol/sdk-config": "0.6.3",
22
- "@cowprotocol/sdk-contracts-ts": "1.1.1",
22
+ "@cowprotocol/sdk-contracts-ts": "1.2.0",
23
23
  "@cowprotocol/sdk-order-book": "0.5.1",
24
- "@cowprotocol/sdk-trading": "0.8.2",
25
- "@cowprotocol/sdk-weiroll": "0.1.12",
26
- "@cowprotocol/sdk-cow-shed": "0.2.11"
24
+ "@cowprotocol/sdk-cow-shed": "0.2.12",
25
+ "@cowprotocol/sdk-trading": "0.9.0",
26
+ "@cowprotocol/sdk-weiroll": "0.1.12"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/jest": "^29.4.0",
@@ -40,9 +40,9 @@
40
40
  "viem": "^2.28.4",
41
41
  "@cow-sdk/typescript-config": "0.0.0-beta.0",
42
42
  "@cowprotocol/sdk-ethers-v5-adapter": "0.3.1",
43
- "@cowprotocol/sdk-ethers-v6-adapter": "0.3.1",
44
- "@cowprotocol/sdk-order-signing": "0.1.25",
45
- "@cowprotocol/sdk-viem-adapter": "0.3.1"
43
+ "@cowprotocol/sdk-order-signing": "0.1.26",
44
+ "@cowprotocol/sdk-viem-adapter": "0.3.1",
45
+ "@cowprotocol/sdk-ethers-v6-adapter": "0.3.1"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsup src/index.ts --format esm,cjs --dts",