@silentswap/sdk 0.1.68 → 0.1.69

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 +11 -25
  2. package/package.json +1 -1
package/dist/bridge.js CHANGED
@@ -2,12 +2,6 @@ import { encodeFunctionData, erc20Abi } from 'viem';
2
2
  import BigNumber from 'bignumber.js';
3
3
  import { NI_CHAIN_ID_AVALANCHE, S0X_ADDR_USDC_AVALANCHE, S0X_ADDR_EVM_ZERO, UINT256_MAX, N_DEBRIDGE_CHAIN_ID_SOLANA, N_DEBRIDGE_CHAIN_ID_TRON, N_RELAY_CHAIN_ID_SOLANA, N_RELAY_CHAIN_ID_BITCOIN, N_RELAY_CHAIN_ID_SUI, N_RELAY_CHAIN_ID_TRON, S0X_ADDR_TRON_NATIVE, SB58_ADDR_SOL_PROGRAM_SYSTEM, } from './constants.js';
4
4
  import { createPhonyDepositCalldata } from './wallet.js';
5
- // TTL cache for solveOptimalUsdcAmount — avoids re-fetching identical quotes
6
- const QUOTE_CACHE_TTL = 30_000; // 30 seconds
7
- const quoteCache = new Map();
8
- function getQuoteCacheKey(srcChainId, srcToken, srcAmount, forceProvider) {
9
- return `${srcChainId}:${srcToken}:${srcAmount}:${forceProvider ?? 'any'}`;
10
- }
11
5
  /**
12
6
  * Map relay.link chain IDs to deBridge chain IDs
13
7
  * Different bridge providers use different chain ID schemes
@@ -800,12 +794,9 @@ async function solveDebridgeSingleChainUsdcAmount(chainId, srcToken, srcAmount,
800
794
  */
801
795
  export async function solveOptimalUsdcAmount(srcChainId, srcToken, srcAmount, userAddress, depositCalldata, maxImpactPercent, depositorAddress, evmSignerAddress, // Optional EVM address for deposit calldata (required for non-EVM swaps: Solana, Bitcoin)
802
796
  forceProvider) {
803
- // Check cache first
804
- const cacheKey = getQuoteCacheKey(srcChainId, srcToken, srcAmount, forceProvider);
805
- const cached = quoteCache.get(cacheKey);
806
- if (cached && Date.now() - cached.timestamp < QUOTE_CACHE_TTL) {
807
- return cached.result;
808
- }
797
+ // Always solve fresh — caching here can desync the destination amounts baked into
798
+ // the order from the bridgeUsdcAmount used at execute time, leading to deposit/approval
799
+ // amount mismatches caught by the solver.
809
800
  // Check if this is a non-EVM chain (Solana, Bitcoin, etc.)
810
801
  const isNonEvmChain = isNonEvmRelayChainId(srcChainId);
811
802
  // For non-EVM chains (Solana, Bitcoin), we need an EVM address for deposit calldata
@@ -873,29 +864,24 @@ forceProvider) {
873
864
  }
874
865
  throw new AggregateError(errors, 'All bridge providers failed');
875
866
  }
876
- // Helper to cache and return result
877
- const cacheAndReturn = (result) => {
878
- quoteCache.set(cacheKey, { result, timestamp: Date.now() });
879
- return result;
880
- };
881
867
  // Only one succeeded
882
868
  if (!relayData) {
883
869
  console.info('Using deBridge (relay failed)');
884
- return cacheAndReturn({
870
+ return {
885
871
  usdcAmountOut: debridgeData.usdcAmountOut,
886
872
  actualAmountIn: debridgeData.actualAmountIn,
887
873
  provider: 'debridge',
888
874
  allowanceTarget: debridgeData.allowanceTarget,
889
- });
875
+ };
890
876
  }
891
877
  if (!debridgeData) {
892
878
  console.info('Using relay.link (deBridge failed)');
893
- return cacheAndReturn({
879
+ return {
894
880
  usdcAmountOut: relayData.usdcAmountOut,
895
881
  actualAmountIn: relayData.actualAmountIn,
896
882
  provider: 'relay',
897
883
  allowanceTarget: relayData.allowanceTarget,
898
- });
884
+ };
899
885
  }
900
886
  // Compare rates (USDC out / amount in)
901
887
  // Use BigNumber for precision (matching Svelte implementation)
@@ -905,21 +891,21 @@ forceProvider) {
905
891
  // Relay performs better (matches Svelte: yx_rate_relay.gte(yx_rate_debridge))
906
892
  if (relayRate.gte(debridgeRate)) {
907
893
  console.info(`Using relay.link: ${relayRate.toString()} >= ${debridgeRate.toString()}`, [relayData.usdcAmountOut, relayData.actualAmountIn], [debridgeData.usdcAmountOut, debridgeData.actualAmountIn]);
908
- return cacheAndReturn({
894
+ return {
909
895
  usdcAmountOut: relayData.usdcAmountOut,
910
896
  actualAmountIn: relayData.actualAmountIn,
911
897
  provider: 'relay',
912
898
  allowanceTarget: '',
913
- });
899
+ };
914
900
  }
915
901
  else {
916
902
  // DeBridge performs better
917
903
  console.info(`Using deBridge: ${debridgeRate.toString()} >= ${relayRate.toString()}`, [debridgeData.usdcAmountOut, debridgeData.actualAmountIn], [relayData.usdcAmountOut, relayData.actualAmountIn]);
918
- return cacheAndReturn({
904
+ return {
919
905
  usdcAmountOut: debridgeData.usdcAmountOut,
920
906
  actualAmountIn: debridgeData.actualAmountIn,
921
907
  provider: 'debridge',
922
908
  allowanceTarget: debridgeData.allowanceTarget,
923
- });
909
+ };
924
910
  }
925
911
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silentswap/sdk",
3
3
  "type": "module",
4
- "version": "0.1.68",
4
+ "version": "0.1.69",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
7
7
  "main": "dist/index.js",