@silentswap/react 0.0.57 → 0.0.59
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.
|
@@ -8,7 +8,7 @@ import { getAssociatedTokenAddress } from '@solana/spl-token';
|
|
|
8
8
|
import { PublicKey } from '@solana/web3.js';
|
|
9
9
|
import { useAssetsContext } from './AssetsContext.js';
|
|
10
10
|
import { usePrices } from '../hooks/usePrices.js';
|
|
11
|
-
import { isSolanaAsset, parseSolanaCaip19, isSolanaNativeToken, isSplToken, isEvmNativeToken, isBitcoinAsset, SB58_CHAIN_ID_SOLANA_MAINNET, A_VIEM_CHAINS, BITCOIN_CHAIN_ID, } from '@silentswap/sdk';
|
|
11
|
+
import { isSolanaAsset, parseSolanaCaip19, isSolanaNativeToken, isSplToken, isEvmNativeToken, isBitcoinAsset, isBitcoinMainnetAsset, SB58_CHAIN_ID_SOLANA_MAINNET, A_VIEM_CHAINS, BITCOIN_CHAIN_ID, } from '@silentswap/sdk';
|
|
12
12
|
const BalancesContext = createContext(undefined);
|
|
13
13
|
// Custom RPC endpoints from 0xrpc.io (fast, free, private public RPC)
|
|
14
14
|
// Reference: https://0xrpc.io
|
|
@@ -366,10 +366,12 @@ const fetchSolanaBalances = async (solAddress, solanaRpcUrl, assets, getUnitValu
|
|
|
366
366
|
return { balances: {}, error: errorMsg };
|
|
367
367
|
}
|
|
368
368
|
};
|
|
369
|
-
// Utility: Fetch Bitcoin native balances using Mempool.space API
|
|
369
|
+
// Utility: Fetch Bitcoin native balances using Mempool.space API (BTC only).
|
|
370
|
+
// Mempool.space is Bitcoin mainnet only; do not assign this balance to BCH or other bip122 chains.
|
|
370
371
|
const fetchBitcoinNativeBalances = async (bitcoinAddress, a_assets_native, getUnitValueUsd) => {
|
|
371
372
|
const updatedBalances = {};
|
|
372
|
-
|
|
373
|
+
const a_btc_only = a_assets_native.filter((a) => isBitcoinMainnetAsset(a.caip19));
|
|
374
|
+
if (a_btc_only.length === 0)
|
|
373
375
|
return updatedBalances;
|
|
374
376
|
try {
|
|
375
377
|
// Fetch balance from Mempool.space API (free, no auth required)
|
|
@@ -384,7 +386,7 @@ const fetchBitcoinNativeBalances = async (bitcoinAddress, a_assets_native, getUn
|
|
|
384
386
|
const funded = BigInt(data.chain_stats?.funded_txo_sum || 0);
|
|
385
387
|
const spent = BigInt(data.chain_stats?.spent_txo_sum || 0);
|
|
386
388
|
const xg_balance = funded - spent;
|
|
387
|
-
await Promise.all(
|
|
389
|
+
await Promise.all(a_btc_only.map(async (k_asset) => {
|
|
388
390
|
let x_value_usd = 0;
|
|
389
391
|
try {
|
|
390
392
|
x_value_usd = await getUnitValueUsd(k_asset, xg_balance);
|
|
@@ -515,7 +517,7 @@ export const BalancesProvider = ({ children, evmAddress, solAddress, solanaRpcUr
|
|
|
515
517
|
finally {
|
|
516
518
|
setLoading(false);
|
|
517
519
|
}
|
|
518
|
-
}, [evmAddress, solAddress, solanaRpcUrl, assets, assetsLoading, getUnitValueUsd]);
|
|
520
|
+
}, [evmAddress, solAddress, bitcoinAddress, bitcoinRpcUrl, solanaRpcUrl, assets, assetsLoading, getUnitValueUsd]);
|
|
519
521
|
// Refetch balances for specific chains only
|
|
520
522
|
const refetchChains = useCallback(async (chainIds) => {
|
|
521
523
|
if (assetsLoading || chainIds.length === 0)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback, useState } from 'react';
|
|
2
|
-
import { isSolanaAsset, isBitcoinAsset, parseEvmCaip19, S_CAIP19_USDC_AVALANCHE, getAssetByCaip19, solveOptimalUsdcAmount, fetchRelayQuote, N_RELAY_CHAIN_ID_SOLANA, N_RELAY_CHAIN_ID_BITCOIN, SB58_ADDR_SOL_PROGRAM_SYSTEM, isSolanaNativeToken, parseSolanaCaip19, EVM_PHONY_ADDRESS, isValidSolanaAddress, isValidBitcoinAddress, isValidEvmAddress, getAddressFromCaip10, S0X_ADDR_USDC_AVALANCHE, isEvmNativeToken, caip19FungibleEvmToken, FacilitatorKeyType, createHdFacilitatorGroupFromEntropy, PublicKeyArgGroups, SB58_CHAIN_ID_SOLANA_MAINNET, caip19SplToken, DeliveryMethod, X_MAX_IMPACT_PERCENT, NI_CHAIN_ID_AVALANCHE, SBTC_ADDR_BITCOIN_NATIVE, } from '@silentswap/sdk';
|
|
2
|
+
import { isSolanaAsset, isBitcoinAsset, parseEvmCaip19, S_CAIP19_USDC_AVALANCHE, getAssetByCaip19, solveOptimalUsdcAmount, fetchRelayQuote, N_RELAY_CHAIN_ID_SOLANA, N_RELAY_CHAIN_ID_BITCOIN, SB58_ADDR_SOL_PROGRAM_SYSTEM, isSolanaNativeToken, parseSolanaCaip19, EVM_PHONY_ADDRESS, isValidSolanaAddress, isValidBitcoinAddress, isValidEvmAddress, getAddressFromCaip10, S0X_ADDR_USDC_AVALANCHE, isEvmNativeToken, caip19FungibleEvmToken, FacilitatorKeyType, createHdFacilitatorGroupFromEntropy, PublicKeyArgGroups, SB58_CHAIN_ID_SOLANA_MAINNET, caip19SplToken, DeliveryMethod, X_MAX_IMPACT_PERCENT, NI_CHAIN_ID_AVALANCHE, SBTC_ADDR_BITCOIN_NATIVE, isEvmAsset, } from '@silentswap/sdk';
|
|
3
3
|
import { getAddress } from 'viem';
|
|
4
4
|
import { BigNumber } from 'bignumber.js';
|
|
5
5
|
/**
|
|
@@ -280,17 +280,22 @@ export function useQuoteCalculation({ address, evmAddress, wallet, depositorAddr
|
|
|
280
280
|
}
|
|
281
281
|
else {
|
|
282
282
|
// Check if contact is a valid EVM address format
|
|
283
|
-
if (
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
283
|
+
if (isEvmAsset(dest.asset)) {
|
|
284
|
+
if (isValidEvmAddress(dest.contact)) {
|
|
285
|
+
// Normalize to checksummed format
|
|
286
|
+
try {
|
|
287
|
+
recipientAddress = getAddress(dest.contact);
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
throw new Error(`Invalid EVM address checksum for destination ${idx}: ${dest.contact}. ${error instanceof Error ? error.message : String(error)}`);
|
|
291
|
+
}
|
|
287
292
|
}
|
|
288
|
-
|
|
289
|
-
throw new Error(`Invalid EVM address
|
|
293
|
+
else {
|
|
294
|
+
throw new Error(`Hex: ${dest.asset} Invalid EVM recipient address for destination ${idx}: ${dest.contact}. Expected 0x-prefixed EVM address or caip10:eip155:*: format.`);
|
|
290
295
|
}
|
|
291
296
|
}
|
|
292
297
|
else {
|
|
293
|
-
|
|
298
|
+
recipientAddress = dest.contact;
|
|
294
299
|
}
|
|
295
300
|
}
|
|
296
301
|
}
|
|
@@ -314,7 +319,7 @@ export function useQuoteCalculation({ address, evmAddress, wallet, depositorAddr
|
|
|
314
319
|
}
|
|
315
320
|
else if (!isDestSolana && !isDestBitcoin) {
|
|
316
321
|
// Validate EVM address format
|
|
317
|
-
if (!isValidEvmAddress(recipientAddress)) {
|
|
322
|
+
if (isEvmAsset(dest.asset) && !isValidEvmAddress(recipientAddress)) {
|
|
318
323
|
throw new Error(`Invalid recipient address type for EVM destination ${idx}: ${recipientAddress}. Expected 0x-prefixed EVM address.`);
|
|
319
324
|
}
|
|
320
325
|
}
|
|
@@ -200,7 +200,6 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
200
200
|
}
|
|
201
201
|
// Create Solana transaction executor
|
|
202
202
|
const solanaExecutor = createSolanaTransactionExecutor(solanaConnector, solanaConnection);
|
|
203
|
-
debugger;
|
|
204
203
|
// For Solana, we still need EVM wallet client for chain switching (if needed)
|
|
205
204
|
// But the actual transaction execution will use Solana executor
|
|
206
205
|
const executeTx = createTransactionExecutor(walletClient, connector, solanaExecutor);
|
|
@@ -247,7 +246,6 @@ export function useTransaction({ walletClient, connector, solanaConnector, solan
|
|
|
247
246
|
setIsLoading(true);
|
|
248
247
|
setError(null);
|
|
249
248
|
try {
|
|
250
|
-
debugger;
|
|
251
249
|
// Create wrapper functions using shared utilities
|
|
252
250
|
const executeTx = createTransactionExecutor(walletClient, connector);
|
|
253
251
|
const switchChain = createChainSwitcher(walletClient, connector);
|
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.59",
|
|
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.
|
|
28
|
-
"@silentswap/ui-kit": "0.0.
|
|
27
|
+
"@silentswap/sdk": "0.0.59",
|
|
28
|
+
"@silentswap/ui-kit": "0.0.59",
|
|
29
29
|
"@solana/codecs-strings": "^5.1.0",
|
|
30
30
|
"@solana/kit": "^5.1.0",
|
|
31
31
|
"@solana/rpc": "^5.1.0",
|