@silentswap/react 0.0.48 → 0.0.49
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.
|
@@ -97,7 +97,6 @@ function SilentSwapInnerProvider({ children, client, evmAddress, solAddress, sol
|
|
|
97
97
|
const { fetchEstimates, isLoading: egressEstimatesLoading, egressQuotes: egressQuotesFromEstimates, ingressQuote: ingressQuoteFromEstimates, depositAmountUsd: depositAmountUsdFromEstimates, bridgeProviderFromQuote, usdcPrice: usdcPriceFromEstimates, } = useEgressEstimates({
|
|
98
98
|
evmAddress,
|
|
99
99
|
solAddress,
|
|
100
|
-
quoteAddress: effectiveQuoteAddress,
|
|
101
100
|
tokenIn,
|
|
102
101
|
inputAmount,
|
|
103
102
|
destinations,
|
|
@@ -3,7 +3,6 @@ import type { Destination } from './useSwap.js';
|
|
|
3
3
|
export interface UseEgressEstimatesOptions {
|
|
4
4
|
evmAddress: `0x${string}` | string | undefined;
|
|
5
5
|
solAddress: string | undefined;
|
|
6
|
-
quoteAddress: string | undefined;
|
|
7
6
|
tokenIn: AssetInfo | null;
|
|
8
7
|
inputAmount: string;
|
|
9
8
|
destinations: Destination[];
|
|
@@ -18,7 +17,7 @@ export interface UseEgressEstimatesOptions {
|
|
|
18
17
|
* Hook to fetch egress estimates and calculate accurate output amounts
|
|
19
18
|
* Matches the behavior of Svelte Form.svelte's fetch_live_estimate()
|
|
20
19
|
*/
|
|
21
|
-
export declare function useEgressEstimates({ evmAddress, solAddress,
|
|
20
|
+
export declare function useEgressEstimates({ evmAddress, solAddress, tokenIn, inputAmount, destinations, splits, updateDestinationAmount, serviceFeeRate, overheadUsd, calculationDirection, setInputAmount, }: UseEgressEstimatesOptions): {
|
|
22
21
|
fetchEstimates: (direction?: "input-to-output" | "output-to-input") => Promise<any>;
|
|
23
22
|
isLoading: boolean;
|
|
24
23
|
error: Error | null;
|
|
@@ -7,7 +7,7 @@ import { usePrices } from './usePrices.js';
|
|
|
7
7
|
* Hook to fetch egress estimates and calculate accurate output amounts
|
|
8
8
|
* Matches the behavior of Svelte Form.svelte's fetch_live_estimate()
|
|
9
9
|
*/
|
|
10
|
-
export function useEgressEstimates({ evmAddress, solAddress,
|
|
10
|
+
export function useEgressEstimates({ evmAddress, solAddress, tokenIn, inputAmount, destinations, splits, updateDestinationAmount, serviceFeeRate = 0.01, overheadUsd = 0, calculationDirection = 'input-to-output', setInputAmount, }) {
|
|
11
11
|
const { estimateOrder, isLoading, error } = useOrderEstimates({
|
|
12
12
|
evmAddress: evmAddress,
|
|
13
13
|
solAddress: solAddress,
|
|
@@ -31,13 +31,13 @@ export function useEgressEstimates({ evmAddress, solAddress, quoteAddress, token
|
|
|
31
31
|
const fetchEstimates = useCallback(async (direction = 'input-to-output') => {
|
|
32
32
|
console.log('[EgressEstimates] Step 1: Starting fetchEstimates', { direction, tokenIn: tokenIn?.caip19, inputAmount, destinationsCount: destinations.length });
|
|
33
33
|
// Validate all required inputs before proceeding
|
|
34
|
+
// Note: quoteAddress is not required for estimates - useOrderEstimates uses fallback addresses when needed
|
|
34
35
|
if (!tokenIn ||
|
|
35
36
|
!tokenIn.caip19 ||
|
|
36
37
|
!inputAmount ||
|
|
37
38
|
parseFloat(inputAmount) <= 0 ||
|
|
38
|
-
destinations.length === 0
|
|
39
|
-
|
|
40
|
-
console.log('[EgressEstimates] Step 1: Validation failed - missing required inputs');
|
|
39
|
+
destinations.length === 0) {
|
|
40
|
+
console.log('[EgressEstimates] Step 1: Validation failed - missing required inputs', { tokenIn, inputAmount, destinations, splits });
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
const estimateKey = `${tokenIn.caip19}-${inputAmount}-${destinations.map((d) => d.asset).join(',')}-${splits.join(',')}`;
|
|
@@ -196,7 +196,6 @@ export function useEgressEstimates({ evmAddress, solAddress, quoteAddress, token
|
|
|
196
196
|
estimateOrder,
|
|
197
197
|
getPrice,
|
|
198
198
|
updateDestinationAmount,
|
|
199
|
-
quoteAddress,
|
|
200
199
|
serviceFeeRate,
|
|
201
200
|
overheadUsd,
|
|
202
201
|
calculationDirection,
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { useCallback, useRef, useState, useMemo } from 'react';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { parseEvmCaip19, parseSolanaCaip19, isEvmNativeToken, isSolanaNativeToken, isSolanaAsset, } from '@silentswap/sdk';
|
|
3
|
+
import { parseEvmCaip19, parseSolanaCaip19, isEvmNativeToken, isSolanaNativeToken, isSolanaAsset, EVM_PHONY_ADDRESS, SB58_ADDR_SOL_PROGRAM_SYSTEM, } from '@silentswap/sdk';
|
|
4
4
|
import { useQuote } from './useQuote.js';
|
|
5
|
-
// Fallback EVM address for egress quotes when evmAddress is not available
|
|
6
|
-
// Egress quotes always start from Avalanche (EVM), so they require an EVM address
|
|
7
|
-
const EVM_PHONY_ADDRESS_FALLBACK = '0x1111111111111111111111111111111111111111';
|
|
8
5
|
/**
|
|
9
6
|
* Hook for fetching both ingress and egress estimates in parallel
|
|
10
7
|
* Matches the behavior of estimate_order() from silentswap-v2-ui/src/web3/estimate.ts
|
|
@@ -21,17 +18,25 @@ export function useOrderEstimates({ evmAddress, solAddress, sourceAsset, maxImpa
|
|
|
21
18
|
// For ingress, we need the address that matches the source chain (not sourceAsset)
|
|
22
19
|
// For egress, we always start from Avalanche (EVM), so we can use evmAddress as default
|
|
23
20
|
// But we'll create separate useQuote instances to handle this correctly
|
|
21
|
+
// Use fallback addresses when wallet is not connected to allow estimates without wallet
|
|
24
22
|
const ingressAddress = useMemo(() => {
|
|
25
23
|
if (sourceAsset) {
|
|
26
24
|
// For ingress, address should match the source chain
|
|
27
|
-
|
|
25
|
+
// Use fallback addresses when wallet is not connected (for estimates without wallet)
|
|
26
|
+
if (sourceAsset.caip19.includes('solana')) {
|
|
27
|
+
return solAddress || SB58_ADDR_SOL_PROGRAM_SYSTEM;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return evmAddress || EVM_PHONY_ADDRESS;
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
|
-
|
|
33
|
+
// Default to EVM fallback if no source asset
|
|
34
|
+
return EVM_PHONY_ADDRESS;
|
|
30
35
|
}, [sourceAsset, solAddress, evmAddress]);
|
|
31
36
|
// For egress, we always start from Avalanche (EVM), so use EVM address
|
|
32
37
|
// If evmAddress is undefined, use the phony EVM address as fallback
|
|
33
38
|
// This ensures egress quotes always use an EVM address format (required for Avalanche origin)
|
|
34
|
-
const egressAddress = evmAddress ||
|
|
39
|
+
const egressAddress = evmAddress || EVM_PHONY_ADDRESS;
|
|
35
40
|
// Initialize useQuote hooks - one for ingress (uses address based on source chain)
|
|
36
41
|
// and one for egress (uses EVM address since egress always starts from Avalanche)
|
|
37
42
|
const ingressQuote = useQuote({
|
|
@@ -39,7 +44,7 @@ export function useOrderEstimates({ evmAddress, solAddress, sourceAsset, maxImpa
|
|
|
39
44
|
maxImpactPercent,
|
|
40
45
|
});
|
|
41
46
|
const egressQuote = useQuote({
|
|
42
|
-
address: egressAddress, // Always an EVM address (either evmAddress or
|
|
47
|
+
address: egressAddress, // Always an EVM address (either evmAddress or EVM_PHONY_ADDRESS)
|
|
43
48
|
maxImpactPercent,
|
|
44
49
|
});
|
|
45
50
|
const { estimateLive: estimateLiveIngress, interpolateSamples: interpolate } = ingressQuote;
|
package/dist/hooks/useQuote.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { NI_CHAIN_ID_AVALANCHE, S0X_ADDR_USDC_AVALANCHE, S_CAIP19_USDC_AVALANCHE, X_MAX_IMPACT_PERCENT, getBridgeQuote as sdkGetBridgeQuote, interpolateSamples as sdkInterpolateSamples, fetchRelayQuote, fetchDebridgeOrder, normalizeAddress, getAssetByCaip19, N_DEBRIDGE_CHAIN_ID_SOLANA, N_RELAY_CHAIN_ID_SOLANA, SB58_ADDR_SOL_PROGRAM_SYSTEM, S0X_ADDR_EVM_RELAY_LINK_DEAD, SB58_ADDR_SOL_RELAY_LINK_RECIPIENT, isSolanaAsset, } from '@silentswap/sdk';
|
|
3
|
+
import { NI_CHAIN_ID_AVALANCHE, S0X_ADDR_USDC_AVALANCHE, S_CAIP19_USDC_AVALANCHE, X_MAX_IMPACT_PERCENT, getBridgeQuote as sdkGetBridgeQuote, interpolateSamples as sdkInterpolateSamples, fetchRelayQuote, fetchDebridgeOrder, normalizeAddress, getAssetByCaip19, N_DEBRIDGE_CHAIN_ID_SOLANA, N_RELAY_CHAIN_ID_SOLANA, SB58_ADDR_SOL_PROGRAM_SYSTEM, S0X_ADDR_EVM_RELAY_LINK_DEAD, SB58_ADDR_SOL_RELAY_LINK_RECIPIENT, isSolanaAsset, EVM_PHONY_ADDRESS, } from '@silentswap/sdk';
|
|
4
4
|
// Constants for estimateLive
|
|
5
5
|
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
6
|
-
const EVM_PHONY_ADDRESS_FALLBACK = '0x1111111111111111111111111111111111111111';
|
|
7
6
|
/**
|
|
8
7
|
* Hook for getting optimized bridge quotes with retention rate tracking
|
|
9
8
|
* Implements the same functionality as estimate.ts from the original app
|
|
@@ -208,14 +207,14 @@ export function useQuote({ address, maxImpactPercent = X_MAX_IMPACT_PERCENT } =
|
|
|
208
207
|
// For EVM ingress, use EVM address (or phony if not available)
|
|
209
208
|
userAddress = normalizedAddress && normalizedAddress.startsWith('0x')
|
|
210
209
|
? normalizedAddress
|
|
211
|
-
:
|
|
210
|
+
: EVM_PHONY_ADDRESS;
|
|
212
211
|
}
|
|
213
212
|
}
|
|
214
213
|
else {
|
|
215
214
|
// For egress, origin is always Avalanche (EVM), so user must be EVM address
|
|
216
215
|
userAddress = normalizedAddress && normalizedAddress.startsWith('0x')
|
|
217
216
|
? normalizedAddress
|
|
218
|
-
:
|
|
217
|
+
: EVM_PHONY_ADDRESS;
|
|
219
218
|
}
|
|
220
219
|
// For Solana, use different chain IDs for different providers
|
|
221
220
|
const relayChainId = isSolanaChain ? N_RELAY_CHAIN_ID_SOLANA : numericChainId;
|
|
@@ -274,7 +273,7 @@ export function useQuote({ address, maxImpactPercent = X_MAX_IMPACT_PERCENT } =
|
|
|
274
273
|
}),
|
|
275
274
|
// For Solana ingress, set recipient to EVM phony address (for Avalanche destination)
|
|
276
275
|
...(isSolanaChain
|
|
277
|
-
? { recipient:
|
|
276
|
+
? { recipient: EVM_PHONY_ADDRESS }
|
|
278
277
|
: {}),
|
|
279
278
|
}
|
|
280
279
|
: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silentswap/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.49",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@ensdomains/ensjs": "^4.2.0",
|
|
26
|
-
"@silentswap/sdk": "0.0.
|
|
27
|
-
"@silentswap/ui-kit": "0.0.
|
|
26
|
+
"@silentswap/sdk": "0.0.49",
|
|
27
|
+
"@silentswap/ui-kit": "0.0.49",
|
|
28
28
|
"@solana/codecs-strings": "^5.1.0",
|
|
29
29
|
"@solana/kit": "^5.1.0",
|
|
30
30
|
"@solana/rpc": "^5.1.0",
|