@silentswap/react 0.0.72 → 0.0.73

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.
@@ -9,6 +9,8 @@ export interface Destination {
9
9
  export interface QuoteCalculationResult {
10
10
  quote: QuoteResponse;
11
11
  usdcAmount: string;
12
+ /** Source amount in smallest units (same as used for the quote request). Use this for order/deposit to avoid mismatch. */
13
+ sourceAmountInUnits: string;
12
14
  facilitatorGroup: HdFacilitatorGroup | undefined;
13
15
  bridgeProvider: BridgeProvider;
14
16
  allowanceTarget: `0x${string}` | undefined;
@@ -30,6 +30,7 @@ export function useQuoteCalculation({ address, evmAddress, wallet, depositorAddr
30
30
  const isSourceSolana = isSolanaAsset(debouncedSourceAsset);
31
31
  const isSourceBitcoin = isBitcoinAsset(debouncedSourceAsset);
32
32
  let usdcAmountOut;
33
+ let sourceAmountInUnitsForQuote;
33
34
  let bridgeProviderResult = 'none';
34
35
  let allowanceTargetResult = undefined;
35
36
  if (isSourceUsdcAvalanche) {
@@ -37,7 +38,8 @@ export function useQuoteCalculation({ address, evmAddress, wallet, depositorAddr
37
38
  if (!assetInfo)
38
39
  throw new Error(`USDC asset not found`);
39
40
  const sourceAmountBN = BigNumber(debouncedSourceAmount);
40
- usdcAmountOut = sourceAmountBN.shiftedBy(assetInfo.decimals).toFixed(0);
41
+ sourceAmountInUnitsForQuote = sourceAmountBN.shiftedBy(assetInfo.decimals).toFixed(0);
42
+ usdcAmountOut = sourceAmountInUnitsForQuote;
41
43
  }
42
44
  else if (isSourceSolana) {
43
45
  // Solana assets - use relay.link only (not deBridge)
@@ -45,7 +47,8 @@ export function useQuoteCalculation({ address, evmAddress, wallet, depositorAddr
45
47
  if (!assetInfo)
46
48
  throw new Error(`Solana asset not found`);
47
49
  const sourceAmountBN = BigNumber(debouncedSourceAmount);
48
- const sourceAmountInUnits = sourceAmountBN.shiftedBy(assetInfo.decimals).toFixed(0);
50
+ sourceAmountInUnitsForQuote = sourceAmountBN.shiftedBy(assetInfo.decimals).toFixed(0);
51
+ const sourceAmountInUnits = sourceAmountInUnitsForQuote;
49
52
  // Parse Solana CAIP-19 to get chain ID and token address
50
53
  const solanaParsed = parseSolanaCaip19(debouncedSourceAsset);
51
54
  if (!solanaParsed)
@@ -89,6 +92,7 @@ export function useQuoteCalculation({ address, evmAddress, wallet, depositorAddr
89
92
  usdcAmountOut = relayQuote.details.currencyOut.amount;
90
93
  bridgeProviderResult = 'relay'; // Solana uses relay only
91
94
  allowanceTargetResult = undefined; // Relay doesn't need allowance target
95
+ // sourceAmountInUnitsForQuote already set above for Solana
92
96
  }
93
97
  else if (isSourceBitcoin) {
94
98
  // Bitcoin assets - only relay.link supports Bitcoin
@@ -96,7 +100,8 @@ export function useQuoteCalculation({ address, evmAddress, wallet, depositorAddr
96
100
  if (!assetInfo)
97
101
  throw new Error(`Bitcoin asset not found`);
98
102
  const sourceAmountBN = BigNumber(debouncedSourceAmount);
99
- const sourceAmountInUnits = sourceAmountBN.shiftedBy(assetInfo.decimals).toFixed(0);
103
+ sourceAmountInUnitsForQuote = sourceAmountBN.shiftedBy(assetInfo.decimals).toFixed(0);
104
+ const sourceAmountInUnits = sourceAmountInUnitsForQuote;
100
105
  // For Bitcoin swaps, we need:
101
106
  // - Bitcoin address for the 'user' parameter in relay quote
102
107
  // - EVM address for the 'recipient' parameter
@@ -131,6 +136,7 @@ export function useQuoteCalculation({ address, evmAddress, wallet, depositorAddr
131
136
  usdcAmountOut = relayQuote.details.currencyOut.amount;
132
137
  bridgeProviderResult = 'relay'; // Bitcoin only supports relay
133
138
  allowanceTargetResult = undefined; // Bitcoin doesn't need allowance
139
+ // sourceAmountInUnitsForQuote already set above for Bitcoin
134
140
  }
135
141
  else {
136
142
  // EVM assets
@@ -153,6 +159,7 @@ export function useQuoteCalculation({ address, evmAddress, wallet, depositorAddr
153
159
  usdcAmountOut = solveResult.usdcAmountOut.toString();
154
160
  bridgeProviderResult = solveResult.provider;
155
161
  allowanceTargetResult = solveResult.allowanceTarget;
162
+ sourceAmountInUnitsForQuote = sourceAmountInUnits; // EVM: use same amount that was sent to solveOptimalUsdcAmount
156
163
  }
157
164
  // Use wallet's facilitator group if available, otherwise create a temporary one
158
165
  let facilitatorGroupForQuote;
@@ -402,12 +409,13 @@ export function useQuoteCalculation({ address, evmAddress, wallet, depositorAddr
402
409
  // Reset loading state only on successful quote
403
410
  setLoadingAmounts(false);
404
411
  }
405
- // Return both quote, usdcAmount, and facilitatorGroup (matches Svelte's solve_uusdc_amount return [usdcAmount, provider, allowanceTarget])
406
- // The facilitatorGroup is resolved during quote fetching and can be reused in executeSwap
412
+ // Return both quote, usdcAmount, sourceAmountInUnits, and facilitatorGroup (matches Svelte's solve_uusdc_amount return [usdcAmount, provider, allowanceTarget])
413
+ // Use sourceAmountInUnitsForQuote for order/deposit so amount always matches what the quote was built with
407
414
  return quoteResult
408
415
  ? {
409
416
  quote: quoteResult,
410
417
  usdcAmount: usdcAmountOut,
418
+ sourceAmountInUnits: sourceAmountInUnitsForQuote,
411
419
  facilitatorGroup: facilitatorGroupForQuote,
412
420
  bridgeProvider: bridgeProviderResult,
413
421
  allowanceTarget: allowanceTargetResult,
@@ -1,7 +1,6 @@
1
1
  import { useCallback, useMemo, useState, useRef, useEffect } from 'react';
2
- import { hexToBase58, isSolanaAsset, isBitcoinAsset, parseEvmCaip19, S_CAIP19_USDC_AVALANCHE, NI_CHAIN_ID_AVALANCHE, getAssetByCaip19, } from '@silentswap/sdk';
2
+ import { hexToBase58, isSolanaAsset, isBitcoinAsset, parseEvmCaip19, S_CAIP19_USDC_AVALANCHE, NI_CHAIN_ID_AVALANCHE, } from '@silentswap/sdk';
3
3
  import { getAddress } from 'viem';
4
- import { BigNumber } from 'bignumber.js';
5
4
  import { useQuoteFetching } from './useQuoteFetching.js';
6
5
  import { useOrderSigning } from './useOrderSigning.js';
7
6
  import { useBridgeExecution } from './useBridgeExecution.js';
@@ -161,18 +160,11 @@ export function useSilentQuote({ client, address, evmAddress, solAddress, wallet
161
160
  // Ensure loadingAmounts is reset if handleGetQuote failed
162
161
  throw new Error('Failed to get quote');
163
162
  }
164
- const { quote: quoteResponse, usdcAmount: effectiveUsdcAmount, facilitatorGroup: passedFacilitatorGroup, bridgeProvider: effectiveProvider, allowanceTarget: effectiveAllowanceTarget, } = quoteResult;
163
+ const { quote: quoteResponse, usdcAmount: effectiveUsdcAmount, sourceAmountInUnits, facilitatorGroup: passedFacilitatorGroup, bridgeProvider: effectiveProvider, allowanceTarget: effectiveAllowanceTarget, } = quoteResult;
165
164
  setCurrentStep('Executing swap...');
166
165
  onStatus?.('Executing swap...');
167
- // Convert source amount to units
168
- const assetInfo = getAssetByCaip19(sourceAsset);
169
- if (!assetInfo) {
170
- throw new Error(`Asset not found: ${sourceAsset}`);
171
- }
172
- const sourceAmountBN = BigNumber(sourceAmount);
173
- console.log('sourceAmountBN', sourceAmountBN);
174
- const sourceAmountInUnits = sourceAmountBN.shiftedBy(assetInfo.decimals).toFixed(0);
175
- console.log('sourceAmountInUnits', sourceAmountInUnits, assetInfo);
166
+ // Use the exact source amount in units from the quote result so order and deposit
167
+ // always match what was requested (avoids rounding/precision mismatch)
176
168
  // Determine provider for bridge swap
177
169
  const isDirectDeposit = sourceAsset === S_CAIP19_USDC_AVALANCHE;
178
170
  let providerForSwap = undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@silentswap/react",
3
3
  "type": "module",
4
- "version": "0.0.72",
4
+ "version": "0.0.73",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -24,8 +24,8 @@
24
24
  "dependencies": {
25
25
  "@bigmi/core": "^0.6.5",
26
26
  "@ensdomains/ensjs": "^4.2.0",
27
- "@silentswap/sdk": "0.0.72",
28
- "@silentswap/ui-kit": "0.0.72",
27
+ "@silentswap/sdk": "0.0.73",
28
+ "@silentswap/ui-kit": "0.0.73",
29
29
  "@solana/codecs-strings": "^5.1.0",
30
30
  "@solana/kit": "^5.1.0",
31
31
  "@solana/rpc": "^5.1.0",