@silentswap/sdk 0.1.55 → 0.1.57

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.
Files changed (2) hide show
  1. package/dist/bridge.js +10 -2
  2. package/package.json +1 -1
package/dist/bridge.js CHANGED
@@ -610,9 +610,14 @@ async function solveDebridgeUsdcAmount(srcChainId, srcToken, srcAmount, userAddr
610
610
  }),
611
611
  });
612
612
  // Calculate price impact
613
+ // Use originApproximateUsdValue when available to exclude prepended operating expenses
614
+ // from the impact calculation. When prependOperatingExpenses=true, approximateUsdValue
615
+ // includes opex which inflates the apparent impact (e.g. 5.2% vs real 0.9%).
616
+ const usdInForImpact = quote.estimation.srcChainTokenIn.originApproximateUsdValue
617
+ ?? quote.estimation.srcChainTokenIn.approximateUsdValue;
613
618
  const usdIn = quote.estimation.srcChainTokenIn.approximateUsdValue;
614
619
  const usdOut = quote.estimation.dstChainTokenOut.approximateUsdValue;
615
- const impactPercent = 100 * (1 - usdOut / usdIn);
620
+ const impactPercent = 100 * (1 - usdOut / usdInForImpact);
616
621
  if (impactPercent > maxImpactPercent) {
617
622
  throw new Error(`Price impact too high: ${impactPercent.toFixed(2)}%`);
618
623
  }
@@ -696,9 +701,12 @@ async function solveDebridgeSingleChainUsdcAmount(chainId, srcToken, srcAmount,
696
701
  }),
697
702
  });
698
703
  // Calculate price impact
704
+ // Use originApproximateUsdValue when available to exclude prepended operating expenses
705
+ const usdInForImpact = quote.estimation.srcChainTokenIn.originApproximateUsdValue
706
+ ?? quote.estimation.srcChainTokenIn.approximateUsdValue;
699
707
  const usdIn = quote.estimation.srcChainTokenIn.approximateUsdValue;
700
708
  const usdOut = quote.estimation.dstChainTokenOut.approximateUsdValue;
701
- const impactPercent = 100 * (1 - usdOut / usdIn);
709
+ const impactPercent = 100 * (1 - usdOut / usdInForImpact);
702
710
  if (impactPercent > maxImpactPercent) {
703
711
  throw new Error(`Price impact too high: ${impactPercent.toFixed(2)}%`);
704
712
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silentswap/sdk",
3
3
  "type": "module",
4
- "version": "0.1.55",
4
+ "version": "0.1.57",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "files": [