@silentswap/sdk 0.1.44 → 0.1.46

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/bridge.js CHANGED
@@ -255,7 +255,12 @@ export async function fetchRelayQuote(params, signal) {
255
255
  const text = await response.text();
256
256
  throw parseQuoteApiErrorResponse(response.status, text);
257
257
  }
258
- return response.json();
258
+ const data = await response.json();
259
+ // Some relay.link endpoints return HTTP 200 with error payloads
260
+ if (data && data.errorCode) {
261
+ throw parseQuoteApiErrorResponse(200, JSON.stringify(data));
262
+ }
263
+ return data;
259
264
  }
260
265
  /**
261
266
  * Parse quote API error response (relay.link or deBridge) and return a user-friendly Error.
@@ -753,12 +758,24 @@ forceProvider) {
753
758
  // Extract results
754
759
  const relayData = relayResult.status === 'fulfilled' ? relayResult.value : null;
755
760
  const debridgeData = debridgeResult.status === 'fulfilled' ? debridgeResult.value : null;
756
- // Both failed
761
+ // Both failed — surface the most relevant inner error message
757
762
  if (!relayData && !debridgeData) {
758
763
  const errors = [
759
764
  relayResult.status === 'rejected' ? relayResult.reason : null,
760
765
  debridgeResult.status === 'rejected' ? debridgeResult.reason : null,
761
766
  ].filter(Boolean);
767
+ // Check inner errors for user-actionable messages before throwing generic AggregateError
768
+ for (const err of errors) {
769
+ if (err instanceof Error) {
770
+ const msg = err.message.toLowerCase();
771
+ if (msg.includes('insufficient funds') || msg.includes('insufficient_funds')) {
772
+ throw new Error('Insufficient funds');
773
+ }
774
+ if (msg.includes('no routes found') || msg.includes('no_swap_routes_found')) {
775
+ throw new Error('No quotes found, try to change input amount');
776
+ }
777
+ }
778
+ }
762
779
  throw new AggregateError(errors, 'All bridge providers failed');
763
780
  }
764
781
  // Only one succeeded
@@ -31,6 +31,7 @@ export declare const SB58_ADDR_SOL_PROGRAM_SYSTEM = "111111111111111111111111111
31
31
  export declare const SB58_ADDR_SOL_RELAY_LINK_RECIPIENT = "CbKGgVKLJFb8bBrf58DnAkdryX6ubewVytn7X957YwNr";
32
32
  export declare const SB58_ADDR_SOL_DEAD = "1nc1nerator11111111111111111111111111111111";
33
33
  export declare const SBTC_ADDR_BITCOIN_NATIVE = "bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8";
34
+ export declare const SBTC_ADDR_BTC_RELAY_LINK_RECIPIENT = "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4";
34
35
  export declare const N_RELAY_CHAIN_ID_SOLANA = 792703809;
35
36
  export declare const N_RELAY_CHAIN_ID_BITCOIN = 8253038;
36
37
  export declare const N_RELAY_CHAIN_ID_TRON = 728126428;
package/dist/constants.js CHANGED
@@ -56,6 +56,9 @@ export const SB58_ADDR_SOL_DEAD = '1nc1nerator11111111111111111111111111111111';
56
56
  // Bitcoin constants
57
57
  // Bitcoin native token address (BTC) used by relay.link
58
58
  export const SBTC_ADDR_BITCOIN_NATIVE = 'bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8';
59
+ // Valid Bitcoin recipient address for relay.link quote estimation (BIP-173 test vector P2WPKH)
60
+ // relay.link rejects the phony zero address (SBTC_ADDR_BITCOIN_NATIVE) as recipient — use this fallback
61
+ export const SBTC_ADDR_BTC_RELAY_LINK_RECIPIENT = 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4';
59
62
  // Relay.link chain IDs for non-EVM chains
60
63
  export const N_RELAY_CHAIN_ID_SOLANA = 792703809;
61
64
  export const N_RELAY_CHAIN_ID_BITCOIN = 8253038;
@@ -1,6 +1,6 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import { fetchRelayQuote, fetchDebridgeOrder, } from './bridge.js';
3
- import { N_DEBRIDGE_CHAIN_ID_SOLANA, N_RELAY_CHAIN_ID_SOLANA, N_RELAY_CHAIN_ID_BITCOIN, SB58_ADDR_SOL_PROGRAM_SYSTEM, SB58_ADDR_SOL_DEAD, SB58_ADDR_SOL_RELAY_LINK_RECIPIENT, SBTC_ADDR_BITCOIN_NATIVE, DEAD_ADDRESS, } from './constants.js';
3
+ import { N_DEBRIDGE_CHAIN_ID_SOLANA, N_RELAY_CHAIN_ID_SOLANA, N_RELAY_CHAIN_ID_BITCOIN, SB58_ADDR_SOL_PROGRAM_SYSTEM, SB58_ADDR_SOL_DEAD, SB58_ADDR_SOL_RELAY_LINK_RECIPIENT, SBTC_ADDR_BITCOIN_NATIVE, SBTC_ADDR_BTC_RELAY_LINK_RECIPIENT, DEAD_ADDRESS, } from './constants.js';
4
4
  const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
5
5
  /**
6
6
  * Map relay.link chain IDs to deBridge chain IDs
@@ -158,6 +158,18 @@ function getQuoteProviderErrorMessage(relayRejection, debridgeRejection) {
158
158
  if (check(relayRejection) || check(debridgeRejection)) {
159
159
  return 'Insufficient funds';
160
160
  }
161
+ const checkNoRoutes = (reason) => {
162
+ if (reason instanceof Error) {
163
+ const msg = reason.message.toLowerCase();
164
+ if (msg.includes('no routes found') || msg.includes('no_swap_routes_found')) {
165
+ return true;
166
+ }
167
+ }
168
+ return false;
169
+ };
170
+ if (checkNoRoutes(relayRejection) || checkNoRoutes(debridgeRejection)) {
171
+ return 'No quotes found, try to change input amount';
172
+ }
161
173
  return 'All quote providers failed';
162
174
  }
163
175
  /**
@@ -422,16 +434,16 @@ forceProvider, tradeType = 'EXACT_INPUT', dstAmount) {
422
434
  if (isDestBitcoin) {
423
435
  // For Bitcoin destinations, relay.link requires:
424
436
  // - user to be the source chain address (EVM address if source is EVM)
425
- // - recipient to be the Bitcoin address
426
- // Note: user is already set to relayUserAddress above, which is correct for the source chain
437
+ // - recipient to be a VALID Bitcoin address (NOT the phony zero address)
438
+ // relay.link returns NO_SWAP_ROUTES_FOUND when recipient is the phony address
427
439
  // Set recipient to Bitcoin address
428
- if (recipientAddress && !recipientAddress.startsWith('0x') && !recipientAddress.startsWith('1111')) {
440
+ if (recipientAddress && !recipientAddress.startsWith('0x') && !recipientAddress.startsWith('1111') && recipientAddress !== SBTC_ADDR_BITCOIN_NATIVE) {
429
441
  // Use provided Bitcoin recipient address
430
442
  relayParams.recipient = recipientAddress;
431
443
  }
432
444
  else {
433
- // Bitcoin requires a valid recipient address
434
- throw new Error('Bitcoin recipient address required for Bitcoin destination');
445
+ // Fallback to a valid Bitcoin address for quote estimation
446
+ relayParams.recipient = SBTC_ADDR_BTC_RELAY_LINK_RECIPIENT;
435
447
  }
436
448
  }
437
449
  else if (isSrcBitcoin) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silentswap/sdk",
3
3
  "type": "module",
4
- "version": "0.1.44",
4
+ "version": "0.1.46",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "files": [